WebClient.DownloadFile - Missing Carriage Returns & Line Feeds

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lila Godel

    #1

    WebClient.DownloadFile - Missing Carriage Returns & Line Feeds

    I am having a problem with the download of web pages via the
    WebClient.Downl oadFile function in the specialized VB.Net 2003 I.E.
    plug-in I am designing to speed up the work on my latest project.

    When I edit the web pages in notepad I see a square wherever I normally
    see a carriage return and a line feed when viewing the source in I.E.

    How can I make the web pages come down readable so I can easily make my
    two manual deletions (different text in each file)?

    The code located in modMain.bas (app has no forms) is as follows:

    Sub SaveFile
    'define variables
    Dim clsWebClient As WebClient = New WebClient
    Dim intFileNameStar t As Integer
    Dim intFilePathStar t As Integer
    Dim strFileName As String
    Dim strLocalFilePat h As String
    Dim strRemoteFilePa th As String

    'intialize variables
    strRemoteFilePa th = System.Environm ent.GetCommandL ineArgs(1).ToSt ring
    intFileNameStar t = (InStrRev(strRe moteFilePath, "/") + 1)
    strFileName = Mid$(strRemoteF ilePath, intFileNameStar t)

    strLocalFilePat h = Left$(strRemote FilePath, (intFileNameSta rt - 2))
    intFilePathStar t = (InStrRev(strLo calFilePath, "/") + 1)
    strLocalFilePat h = Mid$(strLocalFi lePath, intFilePathStar t)

    'download and store file
    clsWebClient.Do wnloadFile(strR emoteFilePath, _
    conCfgInfo.strD efaultParentPat h & _
    strLocalFilePat h & "\" & strFileName)

    'clean up
    clsWebClient.Di spose()

    End Sub

    conCfgInfo.strD efaultParentPat h which contains "D:\Pictures\Bi g Dig\" is
    read from Save File.cfg via another sub. The first command line
    argument is set by VBS code in Save File.htm when I select the right
    click menu Save File... choice in I.E. to the URL of what I right
    clicked on. strLocalFilePat h is set to the last subdirectory in the
    remote path.

    So if strRemoteFilePa th contains

    img001.htm gets downloaded to D:\Pictures\Big dig\f073100\img 001.htm in
    my local file system.
  • Cor Ligthert [MVP]

    #2
    Re: WebClient.Downl oadFile - Missing Carriage Returns & Line Feeds

    Lila,

    That page should be readable for you. However it can be that it is in
    another code style than that you use. Than you have at least to encode it
    using the encoding class.

    Unicode
    Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!


    OS systems
    http://www.microsoft.com/globaldev/r...ocversion.mspx

    Encoding class
    http://msdn.microsoft.com/library/de...classtopic.asp

    I hope this helps,

    Cor


    Comment

    • Lila Godel

      #3
      Re: WebClient.Downl oadFile - Missing Carriage Returns & Line Feeds

      I just found the problem. After numerous revisions to try and get the
      web page to be saved in an encoding different from the Western European
      (Windows Encoding) used by explorer with Auto-Select checked that would
      let notepad render the source properly I noticed that the MS-DOS Editor
      and type command would render the page properly.

      Opening the page in the MS-DOS Editor and using the Save command on the
      File menu would enable me to see the page correctly in notepad, but with
      the source code of the page you get redirected to from
      http://www.bigdig.com/thtml/f073100/img001.htm not the source code for
      http://web.archive.org/web/200210090...100/img001.htm.

      After that I replaced the

      clsWebClient.Do wnloadFile(strR emoteFilePath, _
      conCfgInfo.strD efaultParentPat h & _
      strLocalFilePat h & "\" & strFileName)

      code with

      WriteWebPage(Ge tWebPage(strRem oteFilePath),
      conCfgInfo.strD efaultParentPat h & _
      strLocalFilePat h & "\" & strFileName)

      where the new GetWebPage function returns a string with the source of a
      passed in web page and the new WriteWebPage sub writes a passed in web
      page source to a passed in file name. I placed

      strNewData = Replace(strWebP age, vbLf, vbCrLf)
      'eliminates the display of squares in notepad

      in the WriteWebPage sub just before the PrintLine command.

      As soon as I rebuilt the program and ran it again I got a readable web
      page source (still for the wrong web page).

      A quick check revealed improper VBS code in Save File.htm.

      It originally had:

      if external.menuAr guments.event.s rcElement.tagNa me = "IMG" then
      userURL = external.menuAr guments.event.s rcElement.href
      else
      userurl = external.menuAr guments.event.s rcElement.paren t.href
      end if

      because I could not use
      userURL = external.menuAr guments.event.s rcElement.href for .htm files
      with out getting a script error.

      When I replaced the second occurrence of
      userurl = external.menuAr guments.event.s rcElement.paren t.href with
      userurl = external.menuAr guments.documen t.URL I got the right web page
      complete with carriage returns and line feeds.

      Comment

      Working...