I am working on a Sharepoint Application with Office 365. It is an Auto Hosted App and I want to get the file (excel) stream from document library so i can use openXML to perform further operations. I am getting the exception "The remote server returned an error: (403) Forbidden."
Microsoft.SharePoint.Client.File file = GetTheFileFromTheDocLibrary("excelfile.xlsx");
ClientContext clientContext = new ClientContext(Session["SPHostUrl"].ToString());
FileInformation fInfo = SP.File.OpenBinaryDirect(clientContext, file.ServerRelativeUrl);
// The remote server returned an error: (403) Forbidden.
using (MemoryStream memoryStream = new MemoryStream())
{ // other code
Note: the same code is working in a Provider Hosted Application.