Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 25064

Can't Open Binary Stream of file on Sharepoint Documents

$
0
0

I am trying to read stream from a file on Sharepoint Document library. My app has full control on documents. 

OpenBinaryStream throws exception 403. The code works if I use SharePoint Credentials by providing username and password but I want to do this using oauth

I am using following method to access file.

Microsoft.SharePoint.Client.File file = GetTheFileFromTheDocLibrary("expViewSt.xlsx");
                SharePointContextToken contextToken;
                string accessToken;
                Uri sharepointUrl = new Uri(Session["SPHostUrl"].ToString());
                TokenHelper.TrustAllCertificates();
                string contextTokenString = Session["contextToken"].ToString();
                contextToken =
                    TokenHelper.ReadAndValidateContextToken(contextTokenString, Request.Url.Authority);
                accessToken =
                    TokenHelper.GetAccessToken(contextToken, sharepointUrl.Authority).AccessToken;                 
                ClientContext clientContext = TokenHelper.GetClientContextWithAccessToken(sharepointUrl.ToString(), accessToken); 
                FileInformation fInfo = SP.File.OpenBinaryDirect(clientContext, file.ServerRelativeUrl);


Viewing all articles
Browse latest Browse all 25064

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>