Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I try to download file from googledrive if program version is lower then actual according txt file (1.0.0.1) in dropbox. When I download file, label show me size of file and progress bar download process, this works well, but file is not downloaded in location. Does anyone known why? I would like it to work: After download is completed program exit and start downloaded new program version.

What I have tried:

Dim myCode As Byte()
Dim cesta_souboru As String = "C:\Filip\Etikety\Debug"
Dim file As String = cesta_souboru + "\file.txt"
Dim wc As WebClient

Private Sub posli(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles check_update.Click
    wc = New WebClient()
    Dim filename = "file.txt"
    Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("https://www.dropbox.com/s/uywfkhi7wdqa4en/Version.txt?dl=1")
    Dim response As System.Net.HttpWebResponse = request.GetResponse()
    Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())

    Dim newestversion As String = sr.ReadToEnd()
    MsgBox(newestversion)
    Dim currentversion As String = Application.ProductVersion
    MsgBox(currentversion)
    If newestversion.Contains(currentversion) Then
        MsgBox("Používáte aktuální verzi")
    Else
        MsgBox("Nová verze programu je ke stažení, aktualizuji ji pro vás.")
        Try
            System.IO.File.Delete(file)
        Catch ex As UnauthorizedAccessException
        End Try

        AddHandler wc.DownloadProgressChanged, AddressOf DownloadProgressChanged
        'AddHandler wc.DownloadDataCompleted, AddressOf DownloaddataCompleted
        wc.DownloadDataAsync(New Uri("https://drive.google.com/open?id=0B_pejckobLScTWJhUk9jasfhjk"), cesta_souboru + "\" + filename)

    End If
End Sub
Private Sub DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
    ProgressBar1.Value = e.ProgressPercentage
    lbl_prog_percent.Text = e.ProgressPercentage.ToString() + "%"
    lbl_received.Text = String.Format("{0} MB/s / {1} MB/s", (e.BytesReceived / 1024D / 1024D).ToString(), (e.TotalBytesToReceive / 1024D / 1024D).ToString("0.00"))
End Sub
Private Sub DownloaddataCompleted(ByVal sender As Object, ByVal e As DownloadDataCompletedEventArgs)
    RemoveHandler wc.DownloadProgressChanged, AddressOf DownloadProgressChanged
    RemoveHandler wc.DownloadDataCompleted, AddressOf DownloaddataCompleted
    ProgressBar1.Value = 0
    If e.Error IsNot Nothing Then
        MessageBox.Show(e.Error.Message)
    ElseIf e.Cancelled Then
        MessageBox.Show("Download cancelled by the user")
    Else
        'myCode = e.Result
    End If
    Dim URL As String = DirectCast(e.UserState, String)
    MessageBox.Show(URL)
    Timer5.Start()


End Sub
Private Sub Timer5_Tick(sender As Object, e As EventArgs) Handles Timer5.Tick
    Process.Start(cesta_souboru + "\iMontix.exe")
    Application.Exit()

End Sub
Posted
Updated 22-Feb-19 3:06am
Comments
CHill60 22-Feb-19 3:34am    
Have you tried debugging it?
Member 13711215 22-Feb-19 4:00am    
Hi, yes, the file was searched, the size matches, and the path to upload is also there. I edit DownloaddataCompleted to DownloadstringCompleted

I'm afraid DropBox has tightened their security last year, and it is not simple to use the download URL's anymore. Maybe you can try using their API or use another provider.
 
Share this answer
 
On top of what Rick said, your code is also catching exceptions and doing nothing with them:
C#
Try
    System.IO.File.Delete(file)
Catch ex As UnauthorizedAccessException
End Try

This hides the exception your catching so if the Delete does fail, you have no idea it failed nor do you get any hint as to why. Unless you've got a REALLY good reason for doing so, swallowing exceptions like this is a bad idea.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900