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…