0

how can I upload multiple images using a single file upload control in asp.net web forms?

I am able to upload a single image file using file upload control but I want to make it more dynamic to upload multiple images by using one control.

Can anyone help me out in this?

Thankyou.

2

2 Answers 2

1

You need to use AllowMultiple attribute, like this

<asp:FileUpload id="controlID" runat="server" AllowMultiple="true"/>

Sign up to request clarification or add additional context in comments.

1 Comment

Just wanted to add, the files posted using AllowMultiple="true" can be accessed in the code behind using controlID.PostedFiles.
0

You can't. It is strictly one file per control.

To upload multiple files using one submit button you would need to use Javascript to add more FileControls dynamically, like this (using jQuery):

$(document).ready(function () {

   $("#addAnotherFile").click(function () {
       $("input[type='file']").after('<br /><input type="file" name="file" />');
   }
});

In the submit button handler, you can then enumerate through the Request.Files collection to access your uploads:

for (int i = 0; i < Request.Files.Count; i++)
{
    HttpPostedFile file = Request.Files[i];
    if (file.ContentLength > 0)
    {

 file.SaveAs(Path.Join("Uploaded/Files/Path",Path.GetFileName(file.FileName)));
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.