Computer ForumsComputers  

Go Back   Computer Forums > Programmers Lounge > Programming Discussions > Programming Tips and FAQ

Reply
 
LinkBack Thread Tools Display Modes
Old 07-17-2003, 09:18 PM   #1 (permalink)
Junior Techie
 
Join Date: May 2003
Posts: 82
Default Downloading files in VB.NET

I just thought this could be useful, downloading files using the System.Net namespace .

First of all you have to import the System.Net namespace
Code:
Imports System.Net
Then you need to declare a new instance of a WebClient class which will be used to download the data.
Code:
Dim webc As New WebClient
Now there are two ways you can download, download to a file, or download the data as bytes.
THis is how you would download a file and as bytes:
Code:
Dim data() As Bytes = webc.DownloadData("http://www.tech-forums.net")
This will download the HTML of the main page of the forums. But to the HTML in lets say a textbox you need to translate to a string like this:
Code:
Dim stringdata As String = System.Text.Encoding.Ascii.GetString(data)
Then you can assign it to lets say a textbox to display the html.

Other way is to download things to a file:
Code:
webc.DownloadFile("http://www.tech-forums.net", "C:\techforumshtml.html")
First argument is the address of the file and then the path at which to save it.

I hope this is useful to someone .
__________________
My specs:
AMD Athlon 64 3500 Winchester
MSI Neo2 Platinum NForce3 Ultra
2GB Corsair XMS Ram
520W Aspire Triple Fan PSU
GeForce 6800 Ultra
Sound Blaster Audigy 2 ZS
10,000 RPM 74GB Raptor
120GB Maxtor
Princeton 17\' DVI Monitor
Logitech Cordless Duo MX
Creative P7800 7.1 Speakers
AOpen DVD Dual Layer recorder
Person is offline   Reply With Quote
Old 06-29-2005, 12:45 PM   #2 (permalink)
Newb Techie
 
Join Date: Jun 2005
Posts: 1
Default

excelent, just what i was looking for
Themodem is offline   Reply With Quote
Old 06-29-2005, 01:52 PM   #3 (permalink)
Ultra Techie
 
Join Date: Sep 2003
Location: Bamberg, Germany
Posts: 549
Send a message via ICQ to Iron_Cross Send a message via MSN to Iron_Cross Send a message via Yahoo to Iron_Cross
Default

And the C# version
Quote:
just thought this could be useful, downloading files using the System.Net namespace .

First of all you have to import the System.Net namespace

Code:
using System.Net;
Then you need to declare a new instance of a WebClient class which will be used to download the data.

Code:
WebClient webc = new WebClient();
Now there are two ways you can download, download to a file, or download the data as bytes.
THis is how you would download a file and as bytes:

Code:
byte[] data = webc.DownloadData("http://www.tech-forums.net");
This will download the HTML of the main page of the forums. But to the HTML in lets say a textbox you need to translate to a string like this:

Code:
string stringdata = System.Text.Encoding.Ascii.GetString(data);
Then you can assign it to lets say a textbox to display the html.

Other way is to download things to a file:

Code:
webc.DownloadFile("http://www.tech-forums.net", "C:\techforumshtml.html");
First argument is the address of the file and then the path at which to save it.

I hope this is useful to someone .

__________________

See today\'s Penny-Arcade!(May contain foul lanuage)
Pain is weakness leaving the body.

PM Me for my MSN
Iron_Cross is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:53 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0