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

Wictor Wilén

Microsoft Certified Master (MCM) - SharePoint 2010 | Microsoft Most Valuable Professional (MVP) - SharePoint Server MVP | Author

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 5 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
#  Silverlight by Ted
Screenshot from websnpr What about uploading a document using Silverlight webpart that then writes it to a document library? It seems like that would work, no?
#  SP2010 sandbox solution image upload control not working by Marut
Screenshot from websnpr so what we have to do so that image upload control works properly and upload a file in picture library
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.