Upload multiple files using FileUpload control
ASP.NET allows uploading of files in
very easy way using FileUpload
control. But if you want to allow the user to upload multiple files at once you can use single FileUpload control to
upload multiple files.
The FileUpload control has a property AllowMultiple if it is set to true user can select multiple files
at once. Below is an example of how we can upload multiple files using one
FileUpload control?
Aspx
<asp:FileUpload ID="fileUpload" runat="server" AllowMultiple="true" />
<asp:Button ID="btnUploadFile" runat="server" Text="Upload Image" OnClick="btnUploadFile_Click" />
C#
protected void btnUploadFile_Click(object sender, EventArgs e)
{
if (fileUpload.HasFiles)
{
foreach (HttpPostedFile f in fileUpload.PostedFiles)
{
fileUpload.SaveAs(Server.MapPath("~/UploadedImages/" + f.FileName));
}
}
}
Comments
Post a Comment