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.

2 Answers 2


I was facing the same issue while creating Excel file using Microsoft Interop dll. Solution which worked for me was use impersonation.

In my case service was to be used by anonymous user without any Authentication, but to access Interop dll user should have permission token. so I used impersonation before accessing methods of dll.

Hope this would help you resolve your problem too.


Access the SharePoint Management shell run as administrator and then executed below mentioned command:-

1) Un-provision the reporting service and re-provision

Get-SPServiceInstance -all |where {$_.TypeName -like “SQL Server Reporting*”} | Stop-SPServiceInstance

Get-SPServiceInstance -all |where {$_.TypeName -like “SQL Server Reporting*”} | Start-SPServiceInstance

2) Access the Central Admin > Application management > Manage service application > Select SQL reporting service > In top link bar click on Administrator > added account "[email protected]" gave full permission to this account

3) Once again we navigate to General application setting > Reporting services > we were successfully able to able to navigate "set servers as defaults" option

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.