ArdaZeytin
ArdaZeytin

Reputation: 1324

How can I use "If" for download couldn't completed or download canceled VB.NET

For example ,

My.Computer.Network.DownloadFile("https://dl.dropboxusercontent.com/u/71476794/Afterformatresources/vlc-2.1.2-win32.exe", "c:\Downloads\vlc.exe", "", "", True, 90, True, FileIO.UICancelOption.DoNothing)
    Process.Start("C:\Downloads\vlc.exe")

I want to deactive "process.start" command if download coudn't finish or canceled form user because of the NSIS error.

enter image description here

Upvotes: 1

Views: 325

Answers (2)

ArdaZeytin
ArdaZeytin

Reputation: 1324

There is a working example. I think it will be helpful if someone search this problem.

 Private Sub btnvlc_Click(sender As Object, e As EventArgs) Handles btnvlc.Click
    Try
        My.Computer.Network.DownloadFile("https://dl.dropboxusercontent.com/u/71476794/Afterformatresources/vlc-2.1.2-win32.exe", "c:\Downloads\vlc.exe", "", "", True, 90, True, FileIO.UICancelOption.ThrowException)
        Process.Start("C:\Downloads\vlc.exe")
    Catch ex As Exception
        MsgBox("Download expection occurred:" & vbCrLf & ex.Message)
    End Try
End Sub

Upvotes: 0

Mych
Mych

Reputation: 2553

Use a Try Catch

Try
    My.Computer.Network.DownloadFile("https://dl.dropboxusercontent.com/u/71476794/Afterformatresources/vlc-2.1.2-win32.exe", "c:\Downloads\vlc.exe", "", "", True, 90, True, FileIO.UICancelOption.DoNothing)
    Process.Start("C:\Downloads\vlc.exe")

Catch ex as Exception
    'Exception caught. ex.message will contain some information
    'Handle error with messagebox or other means

Finally
    'Optional for code that will run whether Try was successful or not

End Try

Upvotes: 2

Related Questions