0

I have a provider hosted SharePoint 2013 app. In this app I have a custom ribbon action that when clicked goes to the host web (Default.aspx). On this page I want to create a hash for the selected document in SharePoint with the following code:

Uri FileUri = new Uri(docUrl);
byte[] hashValue;

using (var Client = new WebClient())
{
     hashValue = SHA256Managed.Create().ComputeHash(Client.OpenRead(FileUri));
}
Label2.Text = BitConverter.ToString(hashValue).Replace("-", String.Empty);

docUrl is a string containing the url to the document in SharePoint. In AppManifest.xml Web, SiteCollection and List all have FullControl.

When I run this I get the error 403 forbidden. Is this because the host web does not have access to the document? How can it be fixed?

1 Answer 1

0

I'm 99% sure the issue is that the request being made by the WebClient object does not include the OAuth access token in the headers. That is, you're getting the 403 error because SharePoint can't authenticate the call. Take a look at the code in this blog post for an example of how to get the access token from the context and how to pass it in the message headers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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