2

I want to write an application program that allow you to select multiple file through FileUpload in ASP.NET using C#, how can i do that?

3 Answers 3

2

You can add the allowmultiple property

<asp:FileUpload runat="server" ID="UploadImages" AllowMultiple="true" />

Take a look at this example

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

Comments

2

.NET 4.5 & above :

<asp:FileUpload ID="fileImages" AllowMultiple="true" runat="server" />

.NET 4 and below :

 <asp:FileUpload ID="fileImages" Multiple="Multiple" runat="server" />

html :

<div>
    <asp:FileUpload runat="server" ID="UploadImages" AllowMultiple="true" />
    <asp:Button runat="server" ID="uploadedFile" Text="Upload" OnClick="uploadFile_Click" />
    <asp:Label ID="listofuploadedfiles" runat="server" />
</div>

Button click code :

protected void uploadFile_Click(object sender, EventArgs e)
{
   if (UploadImages.HasFiles)
   {
       foreach (HttpPostedFile uploadedFile in UploadImages.PostedFiles)
       {
           uploadedFile.SaveAs(System.IO.Path.Combine(Server.MapPath("~/Images/"),
           uploadedFile.FileName)); listofuploadedfiles.Text += String.Format("{0}<br />", uploadedFile.FileName);
       }
   }
} 

more reference

Comments

1

You just could write a Submit Controller Method like:

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Submit(IEnumerable<HttpPostedFileBase> files)
{
    //your file code here 
}

and then just offering a corresponding view with any widget for the upload you like and post back the files. e.g. Jquery file upload widget: https://blueimp.github.io/jQuery-File-Upload/

Kendo Ui example in ASP.NET MVC:

 <form method="post" action='@Url.RouteUrl("Default", new {Action =     "Submit"})' style="width:45%">
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)
    <div class="float-left">
    //widget here 
        <p>
            <input type="submit" value="Submit" class="k-button" />
        </p>
    </div>
  </form>

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.