My web form creates Input file controls dynamically using javascript:
var input = document.createElement("input");
input.setAttribute("type", "file");
div.appendChild(input);
How do I get the "PostedFile" from these controls on the server side?
My web form creates Input file controls dynamically using javascript:
var input = document.createElement("input");
input.setAttribute("type", "file");
div.appendChild(input);
How do I get the "PostedFile" from these controls on the server side?
If it posts to the form with everything else then the contents should be in the Request.Files
collection.
The Request.Files collection will contain any files that were posted.
If you prefer FileUpload control, you can generate few of the FileUpload controls on server (either through asp source with runat attribute or through application code) and hide them with css.
<asp:FileUpload ID="FileUpload1" runat="server" runat="server" class="hidden"/>
And then you can enable them with javascript after similar action as you would add new elements.
Then you can use the Files property of the Request object which returns a reference to the HttpFileCollection class. HttpFileCollection class has an Item property through which you get individual HttpPostedFile from the file collection either by specifying the name or index. See Listing 6 for an example.