I'm trying to download a xml file from a website that need to enter username, password, and domain name. I tried to download the file with the correct authentication but I keep getting errors. I'm not too sure where I did wrong. I would appreciate if you can give me a guidance on how to solve the problem. Thank you in advance.
The below is part of my code:
.... string downloadFile = @"C:\Documents and Settings\YY\Desktop\TestFolder\PST.xml"; string temp = node.ChildNodes[i].Attributes[j].Value ; string split = temp.Split('#'); Console.WriteLine(count + " http://awebsite/" + split); WebClient wc = new WebClient(); wc.Credentials = new NetworkCredential("username", "password", "domain" ); wc.DownloadFile("http://awebsite/" + split, downloadFile ); ....
The below is the errors I'm getting: (line 247 is the wc.DownloadFile..... part)
ERROR!: System.Net.WebException: The remote server returned an error: (401) Unauthorized. at System.Net.WebClient.DownloadFile(Uri address, String fileName) at System.Net.WebClient.DownloadFile(String address, String fileName) at TestSharePoint.TestSharePoint.ReadIncidentReport(Lists listService) in C:\Documents and Settings\YY\my documents\visual studio 2010\Projects\TestSharePoint\TestSharePoint\Program.cs:line 247