SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 1 down vote accepted

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

share|improve this answer

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?

share|improve this answer
@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 posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.