|
-
Apr 28th, 2011, 12:08 AM
#1
Thread Starter
Member
[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
-
Apr 28th, 2011, 02:48 AM
#2
Re: problem downloading files
I don't see any downloading there but I do see you using DirectoryExists with a file path.
-
Apr 28th, 2011, 09:23 AM
#3
Thread Starter
Member
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
-
Apr 28th, 2011, 01:19 PM
#4
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 -
-
Apr 28th, 2011, 05:50 PM
#5
Thread Starter
Member
Re: problem downloading files
-
Apr 28th, 2011, 06:30 PM
#6
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?
-
Apr 28th, 2011, 08:57 PM
#7
Thread Starter
Member
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?
-
Apr 28th, 2011, 09:08 PM
#8
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.
-
Apr 28th, 2011, 09:55 PM
#9
Thread Starter
Member
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?
-
Apr 28th, 2011, 10:11 PM
#10
Re: problem downloading files
 Originally Posted by Aest
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.
-
Apr 28th, 2011, 11:08 PM
#11
Re: problem downloading files
 Originally Posted by Aest
im trying to write an updater for my program
Did you consider using ClickOnce?
-
Apr 29th, 2011, 12:47 AM
#12
Thread Starter
Member
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?
-
Apr 30th, 2011, 06:44 AM
#13
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|