How can I use “If” for download couldn't completed or download canceled VB.NET
-
23-12-2019 - |
Вопрос
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.
Решение
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
Другие советы
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
Не связан с StackOverflow