Results 1 to 13 of 13

Thread: [RESOLVED] problem downloading files

  1. #1

    Thread Starter
    Member Aest's Avatar
    Join Date
    Aug 2010
    Posts
    51

    Resolved [RESOLVED] problem downloading files

    im trying to write an updater for my program and im checking the version by downloading a .txt file. however its coming out blank. this is the first time ive done something like this so i probably noobed something bad. any ideas?

    Code:
    Private Sub checkVersion()
    
            Dim strDir As String = ""
            Dim strUrl, strCurVersion, strVersion As String
            Dim sr As IO.StreamReader
    
            getDirectory(strDir)
    
            Form2.Show()
            Form2.lblProg.Text = "Checking Version"
            Form2.Prog.Value = 10
    
            'Download version
            If My.Computer.FileSystem.FileExists(strDir + "\CurrentVersion.txt") Then
                My.Computer.FileSystem.DeleteFile(strDir + "\CurrentVersion.txt")
            End If
    
            My.Computer.Network.DownloadFile("http://www.mediafire.com/file/1323y9ws5n9eosg/KIG_Version.txt", strDir + "\CurrentVersion.txt")
    
            'Load current version
            sr = IO.File.OpenText(strDir + "\CurrentVersion.txt")
            strCurVersion = sr.ReadLine()
            strUrl = sr.ReadLine()
            sr.Close()
    
            'Load old version
            If My.Computer.FileSystem.DirectoryExists(strDir + "\Version.txt") Then
                sr = IO.File.OpenText(strDir + "\Version.txt")
                strVersion = sr.ReadLine()
                sr.Close()
            Else
                strVersion = "0"
            End If
    
            'Compare
            If strCurVersion = strVersion Then
                Form2.lblProg.Text = "No update is available"
            Else
                updateVersion(strUrl, strCurVersion, strVersion)
            End If
    
            Form2.lblProg.Text = "Launching Keep it Green"
            Form2.Prog.Value = 100
    
            runVersion(strCurVersion)
    
        End Sub

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: problem downloading files

    I don't see any downloading there but I do see you using DirectoryExists with a file path.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member Aest's Avatar
    Join Date
    Aug 2010
    Posts
    51

    Re: problem downloading files

    sorry that header is just a cover all for that part of the process. the line is right under that if statement

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: problem downloading files

    Verify that the 1st line of your downloaded version file isn't blank.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  5. #5

    Thread Starter
    Member Aest's Avatar
    Join Date
    Aug 2010
    Posts
    51

    Re: problem downloading files

    its not. my file looks like this:
    1.11
    http://www.mediafire.com/?valhpo6egvptkg0

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: problem downloading files

    Wow. Was that call to DownloadFile there the whole time? I could have sworn not but I see it clear as day now.

    Anyway, I wouldn't worry about checking for an existing file. Just tell DownloadFile to overwrite. Also, you shouldn't keep using strDir + "\CurrentVersion.txt" over and over. Build the file path once and use that over and over.

    So, first things first, download the file and make sure that it contains what you think it does:
    Code:
    'This should not be hard-coded.
    'Store it in the config file or the like so that you can change it without recompiling.
    Dim sourcePath As String = "http://www.mediafire.com/file/1323y9ws5n9eosg/KIG_Version.txt"
    
    Dim targetPath As String = IO.Path.Combine(strDir, "CurrentVersion.txt"
    
    My.Computer.Network.DownloadFile(sourcePath, targetPath, String.Empty, String.Empty, False, 100, True)
    
    MessageBox.Show(IO.File.ReadAllText(targetPath))
    That will display the full contents of the file. Do you see what you expect?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Member Aest's Avatar
    Join Date
    Aug 2010
    Posts
    51

    Re: problem downloading files

    thank you for replying to the post. i like that you just rewrote my code rather than just link me something else. so much easier when its in context. however the files are still showing up empty. even the .exe im trying to update. perhaps its the file hosting site. any recommendations?

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: problem downloading files

    So you're saying that you ran the code that I provided and the message box was empty? If that's the case then the issue is outside your application. Assuming the original files aren't empty, either the server is doing something funky or your computer is.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Member Aest's Avatar
    Join Date
    Aug 2010
    Posts
    51

    Re: problem downloading files

    i think the prob is that the site doesnt support direct linking. any recommendations for free file hosting with direct downloads?

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: problem downloading files

    Quote Originally Posted by Aest View Post
    i think the prob is that the site doesnt support direct linking. any recommendations for free file hosting with direct downloads?
    No, but that's not an issue for the VB.NET forum anyway.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555

    Re: problem downloading files

    Quote Originally Posted by Aest View Post
    im trying to write an updater for my program
    Did you consider using ClickOnce?

  12. #12

    Thread Starter
    Member Aest's Avatar
    Join Date
    Aug 2010
    Posts
    51

    Re: problem downloading files

    well its more for fun and learning than it is practicality i suppose. but i came up with another solution. im not in need of high traffic at all. is there a way i can create a connection to my pc to distribute the update?

  13. #13
    Member
    Join Date
    Mar 2011
    Posts
    55

    Re: problem downloading files

    If your app is publicly available, you will be hammered by bots. I recommend that you don't directly link to your PC.

    To my knowledge, there is no "free" web space that is worth using. You can sign up for a premium account on any of the file sharing sites, then you can use direct linking, or (better idea), just buy a domain and some web space with it.

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