Results 1 to 6 of 6

Thread: download program(update)

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2011
    Posts
    467

    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

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

    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.

  3. #3

    Re: download program(update)

    Quote Originally Posted by SystemX View Post
    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:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3. 'Declare variable
    4. Dim strFile as String = "YOURFILENAME"
    5.  
    6. 'Download the file
    7. My.Computer.Network.DownloadFile("http://yoursite.com/yourfile.exe", strFile)
    8.  
    9. 'Start the installer
    10. Process.Start(strFile)
    11.  
    12. 'Exit the program
    13. End
    14. 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!

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2011
    Posts
    467

    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

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2011
    Posts
    467

    Re: download program(update)

    Quote Originally Posted by despotovski01 View Post
    Try this:
    vb.net Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3. 'Declare variable
    4. Dim strFile as String = "YOURFILENAME"
    5.  
    6. 'Download the file
    7. My.Computer.Network.DownloadFile("http://yoursite.com/yourfile.exe", strFile)
    8.  
    9. 'Start the installer
    10. Process.Start(strFile)
    11.  
    12. 'Exit the program
    13. End
    14. 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.

  6. #6

    Re: download program(update)

    Quote Originally Posted by SystemX View Post
    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:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3.         'Declare a SaveFileDialog to save the file
    4.         Dim saver As New SaveFileDialog
    5.         saver.InitialDirectory = Environment.SpecialFolder.MyDocuments
    6.         saver.Filter = "Executable Files(*.exe)|.exe"
    7.         If saver.ShowDialog = Windows.Forms.DialogResult.OK Then
    8.             My.Computer.Network.DownloadFile("http://yoursite.com/yourfile.exe", saver.FileName)
    9.             'Start the installer
    10.             Process.Start(saver.FileName)
    11.             'Exit the program
    12.             End
    13.         End If
    14.     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
  •  



Click Here to Expand Forum to Full Width