Is it possible to download a file from a website in Windows Application form and put it into a certain directory?
Thanks!
~~Seth
Is it possible to download a file from a website in Windows Application form and put it into a certain directory?
Thanks!
~~Seth
using (WebClient client = new WebClient())
{
client.DownloadFile("http://csharpindepth.com/About.aspx",
@"c:\Users\Jon\Test\foo.txt");
}
Sure, you just use a HttpWebRequest.
Once you have the HttpWebRequest set up, you can save the response stream to a file streamwriter (Either binarystream, or a textwriter depending on the mimetype.) and you have a file on your harddrive.
EDIT: Forgot about WebClient. That works good unless as long as you only need to use GET to retrieve your file. If the site requires you to POST information to it, you'll have to use a HttpWebRequest, so I'm leaving my answer up.
With the WebClient class:
using System.Net;
//...
WebClient Client = new WebClient ();
Client.DownloadFile("http://i.stackoverflow.com/Content/Img/stackoverflow-logo-250.png", @"C:\folder\stackoverflowlogo.png");