<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Multiple files.aspx.cs" Inherits="Multiple_files" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <table> <tr> <td><asp:FileUpload ID="fileupload1" runat="server" /></td> </tr> <tr> <td><asp:FileUpload ID="fileupload2" runat="server" /></td> </tr> <tr> <td><asp:FileUpload ID="fileupload3" runat="server" /></td> </tr> <tr> <td><asp:Button ID="btnuploadall" Text="Upload All" runat="server" onclick="btnuploadall_Click" /></td> <td><asp:Label ID="label1" runat="server"></asp:Label></td> <td><asp:Label ID="label2" runat="server"></asp:Label></td> </tr> </table> </div> </form> </body> </html>
<pre lang="msil">using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Multiple_files : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnuploadall_Click(object sender, EventArgs e) { // string serverFilePath = UpLoad(); //public string MultipleUpLoad(HttpPostedFile selectedFile,int ID,string type) // { string Filepath=null; Filepath= Server.MapPath(@"~\"); HttpFileCollection uploadedFiles = Request.Files; for (int i = 0; i < uploadedFiles.Count; i++) { HttpPostedFile userPostedFile = uploadedFiles[i]; UpLoad1(userPostedFile); } } public string UpLoad1(HttpPostedFile fileToUpload) { string FilePath = null; string Multiplefiles = null; //string[] a = new string[1]; if (fileToUpload.FileName.Length > 0) { FilePath = Server.MapPath(@"~\"); try { string files; string[] UR = fileToUpload.FileName.Split('\\'); //string s2 = (@"\" + fileToUpload.FileName.Split('\\')[UR.Length - 1]); files= fileToUpload.FileName.Split('\\')[UR.Length - 1]; string s1 = FilePath + files; fileToUpload.SaveAs(s1); //fileToUpload.SaveAs(s2); string s = Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/") + files; if (s.Length == 0) label1.Text += "error"+"\n"; else label1.Text += s+ "\n" ; if (FilePath.Length > 0) { Multiplefiles = Server.MapPath(@"~\MultipleFiles"); string s2 = Multiplefiles+ @"\" + files; fileToUpload.SaveAs(s2); // string s2 = //Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/MultipleFiles") + files; if (s1.Length == 0) label2.Text += "Error" + "\n"; else return "";//label2.Text += "Uploaded Successfully"; } } catch { } } return ""; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)