C # version
Upload.aspx
<%@ Page language="c#" codebehind=" upload.aspx.cs" autoeventwireup="false" inherits=" webportal.upload" %> <! DOCTYPE HTML public "-//W3C//DTD HTML 4.0 transitional//en" > < Html> < Head> <title> multi-File upload </title> <script language=" Javascript"> function AddFile () {var str = ' <input type="file" size="50" name=" File"> ' document.getElementById (' MyFile '). insertAdjacentHTML ("BEFOREEND",STR) } </script> </HEAD> <body> <form id="form1" method="post" runat="server" Enctype="multipart/form-data"> <div align="center"> <h3> multi-File upload </h3> < P id=" Myfile"><input type="file" size="50" name=" File"></p> < P> <input type="button" value=" Add (Add) " Onclick="addfile () "> <input Onclick="this.form.reset () " type="button" value=" Reset (reset) "> <asp:button runat="server" text=" Start uploading " id=" Uploadbutton"></asp:button> </P> < P> <asp:label id="strstatus" runat="server" font-names=" Song Body " font-bold=" true" font-size="9pt" width="500px" borderstyle=" none" bordercolor=" White"></asp:label> </P> &lT;/div> </form> </body> </HTML>
UpLoad.aspx.cs
Using System; Using System.Collections; Using System.ComponentModel; Using System.Data; Using System.Drawing; Using System.Web; Using System.Web.SessionState; Using System.Web.UI; Using System.Web.UI.WebControls; Using System.Web.UI.HtmlControls; Summary description of namespace Webportal {///<summary>///UpLoad. Implementation of multiple file upload///</summary> public class Upload:System.Web.UI.Page {protected System.Web.UI.WebControls.Button Uploadbutton; protected system.web . Ui. Webcontrols.label strstatus; private void Page_Load (object sender, System.EventArgs e) {///places user code here to initialize the page if (this. IsPostBack) this. Saveimages (); Private Boolean Saveimages () {///' Traverse File table cell httpfilecollection files = HttpContext.Current.Request.Files;///' state information Sy Stem. Text.stringbuilder STRMSG = new System.Text.StringBuilder (); Strmsg.append (" uploaded files are: <hr color=red>"); try {for (int ifile = 0; ifile < files. Count; ifile++) {///' check file extension name httppostedfile PostedFile = filEs[ifile]; String FileName, FileExtension; FileName = System.IO.Path.GetFileName (postedfile.filename); if (fileName!= "") {fileextension = System.IO.Path.GetExtension (fileName); Strmsg.append (" uploaded file type:" + PostedFile.ContentType.ToString () + "<br>"); Strmsg.append (" Client file address:" + postedfile.filename + "<br>"); Strmsg.append (" upload file filename:" + filename + "<br>"); Strmsg.append ( " upload file extension:" + fileextension + "<br><hr>"); ' Can be saved to a different folder depending on the extended name///Note: You may want to modify the anonymous write permission for your folder. Postedfile.saveas (System.Web.HttpContext.Current.Request.MapPath ("images/") + fileName);} Strstatus.text = Strmsg.tostring (); return true; catch (System.Exception Ex) {strstatus.text = Ex.message; return false;}} Code generated #region The Web Forms Designer override protected void OnInit (EventArgs e) {////CODEGEN: This call is required for the ASP.net Web forms Designer. InitializeComponent (); Base. OnInit (e); }///<summary> The designer supports the method you want-do not use the Code Editor to modify the contents of///this method. </summary> private void InitializeComponent () {this.id = " upload"; This. Load + = new System.EventHandler (this. Page_Load); } #endregion}}