Question

I have a web control with some custom javascript. The javascript creates new file upload controls on the client dynamically using code similar to:

var newFileUpload = document.createElement('input');
newFileUpload.type = 'file';
container.appendChild(newFileUpload); // where container is a div

This exists in an ASP.NET form with encType set to multipart/form-data. I will have 1 - n controls on the page (well, limited to a reasonable number, of course).

I now would like to capture the uploaded files in my ASP.NET application. Because of the approach taken above I know that I cannot capture them as I would from a FileUpload control (which unfortunately I cannot use). Is there another way to capture the uploaded files?

I have looked through a number of areas, including:

  • Request.Files
  • Request.Form
  • Request.Form.Keys
  • Request.InputStream

But I have not been able to find the content. I believe the client is submitting this data correctly but have been unable to determine what the server does with the raw request information (if this is even exposed).

Does anyone have any suggestions on areas I might further explore?

Thanks

Was it helpful?

Solution

You should add a unique name to your upload element to get it from Request.Form collection.

var newFileUpload = document.createElement('input');
newFileUpload.type = 'file';
//newFileUpload.id = 'file01';
newFileUpload.name = 'file01';
container.appendChild(newFileUpload);

EDIT : I tried id and name attibutes, the with name, you can get the content by

Request.Form["file01"]

Also if you should add the attribute below to your form element. This allows you to get the file content by Request.Files["file01"] :

enctype="multipart/form-data"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top