I have a custom web part in a sandbox solution. Inside of the web part I have added an <input type="file" />. Upon postback I read the file using HttpContext.Current.Request.Files and save the file in a document library.

The web part itself lives inside of a custom aspx as a <WebPartPages:SPUserCodeWebPart>. The aspx is deployed as a module and there is no master-page. The only markup in the aspx, except for the web-part is

<form method='post' runat="server" action="FileUploadPage.aspx" enctype="multipart/form-data">

and an <SharePoint:FormDigest> control.

This mechanism works fine when uploading small files. However, if the file being uploaded is larger than 80KB, the web part fails with the dreaded error message:

"Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: An unexpected error has occurred."

This exception cannot be caught via a catch statement and Fiddler tells me that the server returns a regular 200 success response containing the above error message. Also, if I attach a debugger to the web part code, the code is never hit. So, it's not an http error but rather an error that occurs between the moment the POST arrives on the server and the code-behind of the web part is executed.

My only explanation of this error is that there is some arbitrary limit to the size of the http request that you can post in custom aspx pages.

Is there another way of doing a custom file upload? I have considered uploading the file in chunks using AJAX. But I haven't found a way to partially upload a file in a document library.

  • SharePoint pages can only have one form element in them. Does your module create pages that have two?
    – James Love
    Commented Oct 6, 2011 at 13:54
  • @James, no it's only one form tag in the resulting html. Commented Oct 6, 2011 at 13:56
  • Anything in the ULS or server event logs? Commented Jun 12, 2012 at 12:32

1 Answer 1


Have you tried debugging by attaching to the SPUCWorkerProcess.exe?

Also check the resouce limits that are placed on Sandbox solutions here: http://msdn.microsoft.com/en-us/library/gg615462.aspx. That page shows how to remove these limits as well, although that isn't a good idea. I would make this asyncronous rather than syncronous if that is the case. Maybe call a webservice or external API outside of the sandboxed solution.

Hope this helps!

  • Hi, did this answer help? Any updates?
    – mhijazi
    Commented Jun 15, 2012 at 0:57

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.