Download a file from a Claims auth based SharePoint 2010 site programmatically
10,259
Maybe a bit late, but adding the right request header before making the request solves the problem:
webClient.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
Comments
-
turnip_cyberveggie almost 2 years
I have a console application to download a file from a SharePoint site. The sharepoint site uses claims based authentication.
This code throws a 403 Forbidden exception. The specified Network credential has full access to the site, and is able to download the same file from a browser.
WebClient webClient = new WebClient(); webClient.Credentials = new NetworkCredential(username,Password,domain); byte[] fileData = webClient.DownloadData(urlOfAFile); FileStream file = File.Create(localPath); file.Write(fileData, 0, fileData.Length);
Any idea how to fix this?
-
Mikael Svenson almost 14 yearsIs the site set to require ssl (check directoy security in IIS)
-
turnip_cyberveggie almost 14 yearsYes... The site is configured to use HTTPS
-
Admin over 13 yearsAny luck with this problem? I am running into a similar issue.
-
-
turnip_cyberveggie about 13 yearsHi, Thanks for answering. After adding your code snipped, I am getting a 401 Exception. Earlier, I was getting a 403 exception. Am I missing anything?
-
Mel Gerats about 13 yearsAre you trying to log in with Windows authentication or Forms authentication?
-
nixjojo about 12 yearsHi @ashwnacharya Have you solved this problem? I also have the same problem, if you know how to solve it, can you post your answer here? Thanks!
-
Vijay over 11 yearsThis solution worked for me! I tried the other solution provided in the same forum which did not work for me.
-
EthR over 7 yearsI had to add the user agent header also and then it worked. _SPWebClient.Headers["User-Agent"] = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MDDC)";