Add to My Yahoo! | Google Reader or Homepage | Add to Windows Live | Add to Windows Live Alerts

Wictor Wilén

SharePoint Server MVP / Author / MCT / MCTS / MCP / MSc writing about SharePoint and other interesting Microsoft technologies

SharePoint 2010 Sandboxed Web Parts does not support file uploading

Posted at 2010-05-25 01:42 by Wictor Wilén in SharePoint 2010 with 3 comments.

This is just a friendly reminder for you who tries to build a Sandboxed Web Part for SharePoint 2010 and trying to use the FileUpload or HtmlInputFile controls - it will not work. The uploaded files are not transferred to the sandboxed processes and cannot be used in the sandbox.

The SharePoint 2010 sandbox runs in a separate process and all requests from the IIS to SharePoint are marshaled over to the User Code process. It is during this process the files that are uploaded during the request are lost - you will always see that HttpContext.Current.Request.Files.Count is equal to 0, or similar properties on the upload controls are set to null.

For text or XML files it is quite easy to work around using other types of input fields (and optionally some JavaScript hacks).

This is (probably) due to security issues - we do not want user code solutions to be able to upload malicious files to compromise the security.

As always - this was learned the hard way...

Comments and trackbacks

#  Doc Lib by Jaap Vossers
Screenshot from websnpr Definately good to know, although I don't remember the last time I implemented a FileUpload in a web part, as I always let users upload their file(s) in a Document Library and then access this file in my web part code :)
#  @Jaap by Wictor
Screenshot from websnpr Agreed, needed this for a small hobby project... details about this later...
#  Optimize SharePoint Performance; Misconceptions About Cloud Apps; Battle of the Fanboys by Trackback
Screenshot from websnpr Top News Stories 10 Steps to Optimize SharePoint Performance (Network World) SharePoint, the fastest
Make a comment on this post:
Subject:  

Your name:  
Your Url:  
Note: submissions may have to be approved before being visible, so don't submit your comment multiple times.
Real Time Web Analytics