0

I had the below code in a SharePoint Webpart and it worked properly:

using (var wb = new WebClient())
{
    wb.UseDefaultCredentials = true;
    var data = wb.DownloadData(@"http://sharepointSite/_layouts/15/Resources/Stamps/image.png");
}

If I try to use https in browser like:

https://sharepointSite/_layouts/15/Resources/Stamps/image.png

After entering the credential I can download it:

but the problem is where I try to use https in my code:

 using (var wb = new WebClient())
{
    wb.UseDefaultCredentials = true;
    var data = wb.DownloadData(@"https://sharepointSite/_layouts/15/Resources/Stamps/image.png");
}

and I've got error:

The remote server returned an error: (401) Unauthorized.

1 Answer 1

0

I will give my two cents!

Not sure what SharePoint version this is ? On Premises or Cloud ?

Make sure the sharepoint account(the current user of the site) has access to this image. In your code after initialising WebClient , use webClient.UseDefaultCredentials = true;.

Also, prefix @ in front of the URL e.g. @"https://sharepointSite/_layouts/15/Resources/Stamps/image.png"

Let me know how you go.

Thanks Ravi

1
  • Thank you Ravi. It's SharePoint 2013 and installed in the local network on windows server 2013. the url is sample but you must know it works with http and webClient.UseDefaultCredentials = true . I don't know how can I solve it in https. Commented Dec 4, 2017 at 4:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.