I have an application page in LAYOUTS in the 14 hive (SP 2010) within which I am dynamically appending HTML <input type="file"/> controls onto the page. Now when I try to post these files to the server to save them to a document library the HttpContext.Current.Request.Files collection is always empty.
Similar to this question: Sharepoint webpart upload file whitout[sic] using “runat server”
I can not use the <asp:FileUpload/> control with AllowMultiple set to true as there are many metadata input controls that are also being dynamically added to the page. I can not use a static amount of HTML file upload controls either; I have to add additional HTML file input controls client side.
I have found, from both the HttpRequest.Files Property MSDN page as well as various other places (like Request.Files is Empty in a Web Forms Application), that the HTML <form> elements encType value must be set to "multipart/form-data", which I am doing via:
protected void Page_Init(object sender, EventArgs e)
{
Page.Form.Enctype = "multipart/form-data";
}
When debugging the page on post-back, the boundary=... section of the Request.ContentType value is appropriately being appended to the "multipart/form-data" value, but the HttpContext.Current.Request.Files collection is empty. (A nice explanation of the purpose of the boundary data is available in Scott Hanselman's blog post A Back To Basics Case Study: Implementing HTTP File Upload with ASP.NET MVC including Tests and Mocks). You can see the behavior I'm talking about in the debugger here:

Is this something to do with how requests are being handled for the Layouts directory? Or am I just missing something? Any help or pointers are greatly appreciated.