Archive

Archive for April, 2016

Upload multiple files with ASP.Net 4.5

April 5, 2016 Leave a comment

Hi all,

Try this example to Upload multiple files with ASP.Net 4.5 in Visual Studio 2012 and Visual Studio 2013

ASPX Page :

<asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="true" />
<asp:Button ID="btnUpload" Text="Upload" runat="server" OnClick ="UploadMultipleFiles" accept ="image/gif, image/jpeg" />
<asp:Label ID="lblSuccess" runat="server" ForeColor ="Green" />

In Code behind :

protected void UploadMultipleFiles(object sender, EventArgs e)
{
foreach (HttpPostedFile postedFile in FileUpload1.PostedFiles)
{
string fileName = Path.GetFileName(postedFile.FileName);
postedFile.SaveAs(Server.MapPath("~/Uploads/") + fileName);
}
lblSuccess.Text = string.Format("{0} files have been uploaded successfully.", FileUpload1.PostedFiles.Count);
}

Hope this helps

Good Luck.

Categories: ASP.Net