Download a file with credentials - username and password - in C#
By [)ia6l0 iii
Use the System.Net.WebClient class to download a file with credentials.
See the following example,
WebClient downloadWC = new WebClient();
downloadWC.Credentials = new System.Net.NetworkCredential("egg", "kiosk");
byte[] buff = downloadWC.DownloadData("http://www.downloads.com/files/file.txt");
using (System.IO.FileStream fs = new FileStream(@"X:\downloads\file.txt", FileMode.Create))
{
fs.Write(buff,
0, buff.Length);
fs.Close();
}
Related FAQs
Use the following code snippet to download an image from an URL.
Use the WebClient class from System.Net namespace to download and save a file.
Download a file with credentials - username and password - in C# (2985 Views)