Thursday, 2024-11-21, 2:08 PM

NubSoft

Main | Registration | Login
Welcome Guest
RSS
Login form
Search
Site friends
Statistics
Catalog categories
Programming Articles [1]
Programming Articles: C#, Visual Basic.NET
Our poll
Best CLR Programming Language
Total of answers: 40

Articles


Main » Articles » Programming Articles

Download File From the Internet
To download files from the internet we are gonna use a .net object called WebClient.

C#:
System.Net.WebClient client = new System.Net.WebClient();
client.DownloadFile("http://site.com/files/file.zip", "downloads/files.zip");

VB:
Dim client As new System.Net.Webclient()
client.DownloadFile("http://site.com/files/file.zip", "downloads/files.zip")

Pretty easy, isn't it?
The first parameter is the url of the file to download, the second one is where you want to save it, as the name of the file to save, in this example it will save it in a folder called donwloads, and with the same name.

Now, lets make an easy example with Visual Basic. Open Visual Basic 2008 Express Edition, and make a new project. Name it as you wish, and drag 2 textareas, 1 button and 1 label. Make it look like this



Now, double click in the button, and add this code

 Dim client As New System.Net.WebClient()
  Try
      client.DownloadFile(TextBox1.Text, TextBox2.Text)
   Catch ex As Exception
       MsgBox(ex.ToString())
   End Try

That's it, a very basic file download.

Hope you find this useful :)
Category: Programming Articles | Added by: fedekun (2008-09-16) | Author: Federico
Views: 4744 | Rating: 5.0/2 |
Total comments: 0
Only registered users can add comments.
[ Registration | Login ]
Copyright Nubsoft © 2024