-
Sep 7th, 2011, 08:26 AM
#1
Thread Starter
Hyperactive Member
download program(update)
Hi, i have made a program and added a update check button.
If an update is available it lets the user know and if they click update a hidden webbrowser goes to the download address like:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.Navigate("http://mydomain.com/myprogram.exe")
End Sub
Well this works and prompts the user with a file download dialog(default for windows)
But say they have "myprogram.exe" on there desktop and try to save the new updated one there it will ask to overwrite and thats fine but the program is in use as they have click update.
Is there a way to do something about this ?
i tryed:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.Navigate("http://mydomain.com/myprogram.exe")
form1.close()
End Sub
But it closed the form befor it poped up file download dialog. Yes i could use like a 3 second timer but some people internets are fast and some are slow so this isent really the best way to go.
Any help on this would be great
Thanks
-
Sep 7th, 2011, 08:32 AM
#2
Re: download program(update)
Don't use a WebBrowser control unless you want to display a web page to the user. If all you want to do is download a file then use a WebClient and call DownloadFile or even just use My.Computer.Network.DownloadFile.
Basically, a program can't update itself. ClickOnce apps get updated by ClickOnce, which is part of the .NET Framework, not part of the app. If you want to update your app yourself then you need another app to do it. Your shortcut can start an updater app that will download and/or install the new app and then run it.
-
Sep 7th, 2011, 08:37 AM
#3
Lively Member
Re: download program(update)
Originally Posted by SystemX
Hi, i have made a program and added a update check button.
If an update is available it lets the user know and if they click update a hidden webbrowser goes to the download address like:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.Navigate("http://mydomain.com/myprogram.exe")
End Sub
Well this works and prompts the user with a file download dialog(default for windows)
But say they have "myprogram.exe" on there desktop and try to save the new updated one there it will ask to overwrite and thats fine but the program is in use as they have click update.
Is there a way to do something about this ?
i tryed:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.Navigate("http://mydomain.com/myprogram.exe")
form1.close()
End Sub
But it closed the form befor it poped up file download dialog. Yes i could use like a 3 second timer but some people internets are fast and some are slow so this isent really the best way to go.
Any help on this would be great
Thanks
Try this:
vb.net Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Declare variable
Dim strFile as String = "YOURFILENAME"
'Download the file
My.Computer.Network.DownloadFile("http://yoursite.com/yourfile.exe", strFile)
'Start the installer
Process.Start(strFile)
'Exit the program
End
End Sub
First, we declare a string variable, which will hold the file path where we want to save the file (Example: C:\myprogram.exe). Then, we download the file, and finally, we start the installer and close the program. Hope this helps!
-
Sep 7th, 2011, 08:39 AM
#4
Thread Starter
Hyperactive Member
Re: download program(update)
ok, well the webbrowser will be hidden and reason for a webbrowser is because thats the only way i know how to do it atm untill i learn more.
I guess the easyest way would be to append the .exe program with its version number like myprogram-v1.1.exe
Thanks
-
Sep 7th, 2011, 08:41 AM
#5
Thread Starter
Hyperactive Member
Re: download program(update)
Originally Posted by despotovski01
Try this:
vb.net Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Declare variable Dim strFile as String = "YOURFILENAME" 'Download the file My.Computer.Network.DownloadFile("http://yoursite.com/yourfile.exe", strFile) 'Start the installer Process.Start(strFile) 'Exit the program End End Sub
First, we declare a string variable, which will hold the file path where we want to save the file (Example: C:\myprogram.exe). Then, we download the file, and finally, we start the installer and close the program. Hope this helps!
I would like it for the user to select where to download myprogram.exe and its a stand alone program, does not need an installer.
also it throws and error because the file already exsits.
"Could not complete operation since a file already exists in this path 'myprogram.exe'."
Thanks
Last edited by SystemX; Sep 7th, 2011 at 08:45 AM.
-
Sep 7th, 2011, 12:52 PM
#6
Lively Member
Re: download program(update)
Originally Posted by SystemX
I would like it for the user to select where to download myprogram.exe and its a stand alone program, does not need an installer.
also it throws and error because the file already exsits.
"Could not complete operation since a file already exists in this path 'myprogram.exe'."
Thanks
Ok, then try this code:
vb.net Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Declare a SaveFileDialog to save the file Dim saver As New SaveFileDialog saver.InitialDirectory = Environment.SpecialFolder.MyDocuments saver.Filter = "Executable Files(*.exe)|.exe" If saver.ShowDialog = Windows.Forms.DialogResult.OK Then My.Computer.Network.DownloadFile("http://yoursite.com/yourfile.exe", saver.FileName) 'Start the installer Process.Start(saver.FileName) 'Exit the program End End If End Sub
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
|