Uploading Files Using Multiple File Uploads in the same Page
Hello Guys,Today I will be showing you how to upload multiple files using multiple File Uploads in the same Page. There are other alternatives for this as well like as AJAX FileUpload with Progressbar or Jquery Fileupload; but I am just trying to achieve the same using Multiple File Uploads in the same Page.. So Here is how can we achieve the same:
Design Part:
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Multiple File Upload</title> </head> <body> <form id="form1" runat="server"> <div lang="aa" style="font-family: 'Curlz MT'; font-weight: bold; text-decoration: blink; font-style: oblique; text-transform: inherit;"> <h1>Upload Multiple Files in Asp.net Using C# code</h1></div> <div><asp:FileUpload ID="FileUpload1" runat="server" /> <br /> <asp:FileUpload ID="FileUpload2" runat="server" /> <br /> <asp:FileUpload ID="FileUpload3" runat="server" /> <br /> <asp:FileUpload ID="FileUpload4" runat="server" /> </div> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Upload Files" /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </form> </body> </html>
Code Behind:
protected void Button1_Click(object sender, EventArgs e) { HttpFileCollection multipleFiles = Request.Files; for (int fileCount = 0; fileCount < multipleFiles.Count; fileCount++) { HttpPostedFile uploadedFile = multipleFiles[fileCount]; string fileName = Path.GetFileName(uploadedFile.FileName); if (uploadedFile.ContentLength > 0) { uploadedFile.SaveAs(Server.MapPath("~/Files/") + fileName); Label1.Text += fileName + "Saved <BR>"; } } }
No comments:
Post a Comment
Thank You for Your Comments. We will get back to you soon.