I am accessing the document from the SharePoint Doc Library from the Azure Web API Hosted on the Azure. List item i can access properly. but, when I am trying to read the document Getting the error message The remote server returned an error: (401) Unauthorized.
Below is the code which i have written.
var userToken = this.Request.Headers.Authorization.Parameter;
var newToken = await GetSharePointAccessToken(doc.sharePointUrl, userToken);
using (var context = new ClientContext(doc.sharePointUrl))
{
context.ExecutingWebRequest +=
(s, e) => e.WebRequestExecutor.WebRequest.Headers.Add(
"Authorization", "Bearer " + newToken);
var web = context.Web;
var oList = web.Lists.GetByTitle("Employee");
ListItem item = oList.GetItemById(doc.docID);
context.Load(item);
context.Load(item, i => i.File);
context.ExecuteQuery();
FileInformation fInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(context, item["FileRef"].ToString());
var fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(context, fileRef);
}
At this line I am getting the exception
FileInformation fInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(context, item["FileRef"].ToString());