Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

HttpContext.Current.Response.Clear();

HttpContext.Current.Response.AddHeader("content-disposition", 
     String.Format("attachment;filename={0}", "performance.xlsx"));

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

memStream.WriteTo(HttpContext.Current.Response.OutputStream);

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

This works fine on a normal ASP.NET app.

share|improve this question
add comment

2 Answers

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
add comment

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
add comment

Your Answer

 
discard

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.