Downloading a file from a website

C

Chris Morrison

Hi all,

Can anyone tell me which .NET class I need (or provide a code sample) to
download file from a website/url (Not FTP) and save it to my hard drive.

Kind regards,



Chris
 
S

Scott M.

What do you want to do? You don't need .NET for that. <A
HREF="file.ext">Click to download</A>


"Chris Morrison"
 
V

Vijayakrishna Pondala

use the following code:

url - the url of the file to be downloaded.
// Create a request to the URL.

WebRequest request = WebRequest.Create(url);

// Get response from the request made, as a stream

WebResponse response = request.GetResponse();

Stream stream = response.GetResponseStream();

StreamReader reader = new StreamReader(stream);

// read the content of the stream as a string.

string content = reader.ReadToEnd();

// save the same in a temp file.

"Chris Morrison"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top