Friday, February 6, 2009

Request file from javascript created file uploads

If you want the files from your file uploads you normally use:


But when the file uploads is created using javascript like so:

var element = document.getElementById("ctl00_ContentPlaceHolder1_DdlFileCount");

var Value = element[element.selectedIndex].value;

var container = document.getElementById("TextboxContainer");

container.innerHTML = "";

for (var i = 0; i < Value; i++) {

    container.innerHTML += "<input class='textbox' type='file' name='FileUpl" + i + "' id='FileUpl" + i + "' /><br />";


The Request.Files won't detect the files uploaded by the client using the dynamic file upload.

The reason why, is because at compile time creates an Enctype in the form, this wont get created when client-side scripting is doing the creating of control.

My friend found a pretty simple solution, where you just need to add the following line to your page load event:

Form.Enctype = "multipart/form-data";

After that you are able to Request.Files like you normally would do from controls.

No comments:

Post a Comment