To download a file to your computer you'll use:
The most simple way for downloading a file is to only set a string for the URL to download from and a string for the path telling us where on the computer it should be saved on. But since we'll later on(with more advanced downloading options) can't use a string for the URL since that will not be a combination of parameters that exists we'll start to use the Uri type from the beginning, to create a new Uri you just type new Uri([the URL as string]). So it will basically be just like adding it as a string. So to download a file you can do something like this:
My.Computer.Network.DownloadFile(New Uri("http://vswe.codecall.net/Test.txt"), "C:/Test.txt")
Most files that could be downloaded on the internet doesn't need any username or password to be downloaded, so username and password will only be used when downloading private files on your own server, when uploading files you'll have to add usernames and password most of the time since you can't upload files to just any web site, you need to have access to upload them, but more to that later. Since we only want to download "normal" files we'll just leave username and password blank:
My.Computer.Network.DownloadFile(New Uri("http://vswe.codecall.net/Test.txt"), "C:/Test.txt", "", "")
Now we we can also add some UI fi we want, this UI is a box showing the file which is being downloaded, the progress for that file and also a cancel button, when pressing this cancel button the default thing is that an exception is thrown but we can change that later if we want to. The default value for the UI is false so if you don't want to add it just write False instead, but we're going to add the, but there's no option only adding the UI. To be able to set it we also have to set connectionTimeout and overwrite.
ConnectionTimeout is how long time in milliseconds it will try to download the file before it gives up, the default value is 100 seconds (100,000 milliseconds).
Overwrites is a boolean value indicating if it will try to overwrite a file if it already exists, this value is false by default and if it's false and the file does already exists an error will occur. By adding these three values our code can now look like this:
My.Computer.Network.DownloadFile(New Uri("http://vswe.codecall.net/Test.txt"), "C:/Test.txt", "", "", True, 60000, True)
Now we can also set what will happen if the user clicked cancel on the UI. The default value is FileIO.UICancelOption.ThrowException which will throw an exception as you can hear, the other thing is that you set it to don't do anything if the user clicks cancel by using FileIO.UICancelOption.DoNothing. Now our downloading could look like this:
My.Computer.Network.DownloadFile(New Uri("http://vswe.codecall.net/Test.txt"), "C:/Test.txt", "", "", True, 60000, True, FileIO.UICancelOption.DoNothing)
To upload a file to a server you use:
I won't explain the Uploading as much as the downloading since many things works the same in the both of them. When uploading you're writing the local path on the computer first, you'll always write where you're getting the file from first and then where you want to upload/download it to. When uploading a file you need to have a server to upload it to, you also need a username and a password to the server to be able to upload the file to it. Also note how the example URL looks like:
My.Computer.Network.UploadFile("C:\Test.txt", New Uri("ftp://vswe.codecall.net/public_ftp/Test.txt"), "******", "*******")
And the rest of the uploading features is the same as for downloading so I won't teach you anything more about uploading. So that was this tutorial. I hope you enjoyed it and also learned something from it