Download File Using Webrequest With Credentials In C#
Here's a C# code that will download a file from source with credentials (password and username). This assumes that the source directory is password protected. HttpWebRequest request; HttpWebResponse response = null ; try { string username = "xxxuser" ; string password = "yyypass" ; NetworkCredential myCredentials = new NetworkCredential(username, password); request = (HttpWebRequest)WebRequest.Create(ListURL); request.Timeout = 900000000; request.Credentials = myCredentials; request.AllowWriteStreamBuffering = false ; response = (HttpWebResponse)request.GetResponse(); Stream s = response.GetResponseStream(); //Write to disk FileStream fs = new FileStream( "\\192.168.3.3\xmldata.xml" , FileMode.Create); byte []