Results 1 to 9 of 9

Thread: [RESOLVED] Downloading a .txt loses it's formatting

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Resolved [RESOLVED] Downloading a .txt loses it's formatting

    Hi all,

    I have a .txt file stored on a server, not it's pretty well formatted with paragraphs, spacing, tabs, and even bullet points. When accessed directly with the browser, it displays fine. However, using Inet's GET method:

    Code:
    TextIn = WebInet.OpenURL("http://URLHERE/DIR/Assign.txt")
    Open "C:\Assign.txt" For Output As #FF
    Write #FF, TextIn
    Close #FF
    
    
    DFU
    Shell "notepad.exe C:\Assign.txt", vbNormalFocus
    Or the "DownloadFromURL" method:

    Code:
    Private Sub DownLoadFromURL(ByVal url As String, ByVal filename As String)
        '
        '   Download a file from a given URL
        '
        Dim bytes() As Byte
        Dim fnum As Integer
        Dim ftext As String
        '
        ' Download the file and load into byte array
        '
        ftext = url & filename
        bytes() = WebInet.OpenURL(ftext, icByteArray)
    
        fnum = FreeFile
        '
        '   Write the downloaded file to disk
        '
        Open "C:\" & filename For Binary Access Write As #fnum
        
        Put #fnum, , bytes()
        Close #fnum
        
    End Sub
    
    
    
    DownLoadFromURL "http://URL/DIR", "Assign.txt"
    Just download the text file as one huge block of text, unformatted, with wierd characters where the bullets / tabs should be. How can I download the file and retain it's original formatting? I can use this GET method to download a .doc of the same file, and it stays completely in tact

    Thanks

  2. #2
    Hyperactive Member umilmi81's Avatar
    Join Date
    Sep 2005
    Location
    Sterling Heights, Mi.
    Posts
    335

    Re: Downloading a .txt loses it's formatting

    It's because you are making a request to the web server. It's streaming back what a webserver would be able to interpret.

    You should download it with FTP. I'm afraid I don't know how to use the INet control to do FTP. I always use a batch file to do my FTP.

    To make a batch file for FTP. Write the FTP commands to a text file, and then call:

    ftp -vin < ftpcommands.txt > ftpoutput.txt

    with a shell or ShellAndWait.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Re: Downloading a .txt loses it's formatting

    Fair enough ^_^
    Can anyone explain how to download it via FTP though, differentl to what I've already done? I used an FTP command, with an FTP Inet.. I can't remember the exact one, but I know it needed my domain, username, and pass.. I think it didn't return the file at all

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Downloading a .txt loses it's formatting

    I think that there is a problem with the file, which involves the format on the server. It is probably not a Windows server, and there isn't a VbCrLf isn't.
    Post some of the file, so we can see it.

    You can also try the Internet Control. Here is an example:
    Attached Files Attached Files

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Re: Downloading a .txt loses it's formatting

    Yeah, I use the Inet control ^_^

    The server is my free hosting for my cable connection, NTL. We get like, 20 megs of free space, so yeah, it's probably Linux or something. I would use my own server, but my FTP server has stopped working properly recently.. My dyndns has too, maybe it just needs a format.

    Anyhow, here's a link to the file itself:
    Link
    It's my college assignment. I just made it into a .txt from a doc and uploaded it to test the system (I need to do this for another program, too).

    Here's a link to the file AFTER it had been downloaded:
    Link

    I tried loading it on a new form as well, reading the file in one line as a time and adding it to the textbox, with a breakline inbetween each line. It just gave me a horribly contorted version of the file with odd sets of words on one line, like between 2 and 6 words per line


    EDIT:

    I just realised, that when I'd uploaded the horibly screwed up file back onto my server, it viewed fine again in a text browser! I then put the second file on my own server instead, and again, it looks file!

    Here's a screenshot of what it looks like to me, accessed locally:

    Link
    Last edited by BubbleLife; Dec 11th, 2005 at 02:50 PM.

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Downloading a .txt loses it's formatting

    Did you save it as a textfile in Word or Wordpad, or did you try to copy/paste it into notepad? Fx opened the first one fine, and the second one with a few spacing errors. Nothing like the image though. Did you upload it as a text file, or a binary?

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Re: Downloading a .txt loses it's formatting

    I originally wrote the file in Word, and copied the text into Notepad and saves it as a .txt, where originally (stored locally) the layout and formatting appeared file. I didn't actually upload it with VB at all, I uploaded it with my FTP program. I'm not sure what kind of uploading that uses though...

  8. #8
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: Downloading a .txt loses it's formatting

    Quote Originally Posted by Arby
    I originally wrote the file in Word, and copied the text into Notepad and saves it as a .txt, where originally (stored locally) the layout and formatting appeared file. I didn't actually upload it with VB at all, I uploaded it with my FTP program. I'm not sure what kind of uploading that uses though...
    I think it is not a problem because of uploading and downloading or other server issue. I got the same issue as depicted in the picture (notepad) when I opened the same in Notepad.

    When I opened the same in Word there is no issue. And I also tried with some other text editors and i got no issue.

    I think its because of word formatting like tab etc. As you said you typed the data in ms word and you copied it into notepad and you saved the file. but some sort of formatting retains in that file. So, you are getting these issues.
    CS

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Re: Downloading a .txt loses it's formatting

    Ah, I see

    Well, thanks for the help ^_^

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width