I am having trouble writing a file to the response stream (sandbox solution).

The final line of this code block throws a null reference exception.


     String.Format("attachment;filename={0}", "performance.xlsx"));

HttpContext.Current.Response.ContentType = 
     "application/vnd.openxmlformats officedocument.spreadsheetml.sheet";


HttpContext.Current.Response.End() (This line);

This works fine on a normal ASP.NET app.


Due to the limitations of a sandbox solution you cannot achieve what you want to do.

This will have to be done as a Farm solution as the Namespaces you are trying to use are restricted.

(Please someone prove me wrong) :(

There are a few extra for 365, but the ones that effect you cross over.

Sandbox/365 Namespace Rules


The Sandbox lives in it's own process and the HttpContext.Current is different from the HttpContext.Current in ASP.NET (that lives in IIS and the W3WP.exe process). Learn more about limitations of Sanbox solutions in Wictor's post.

Have you tried alternative approach of using the the embedded resources?

  • @user1786107 An embedded resource perhaps wouldn't work though, I know I am presuming but that spreadsheet would want to be editable, i.e. in a document library?
    – Hugh Wood
    Nov 20 '12 at 15:34

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.