HTML 特别要注意的是这行代码 <form id="Form1" method="post" runat="server" enctype="multipart/form-data"> <%...@ Page language="c#" Codebehind="MultiFileUp.aspx.cs" AutoEventWireup="false" Inherits="Vista.Project.MultiFileUp" %><%...@ Register TagPrefix="uc1" TagName="pageHead" Src="../Head/pageHead.ascx" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ><HTML> <HEAD> <title>MultiFileUp</title> <script lang="JavaScript">... function addFile() ...{ var str = '<input type="file" size="50" Name="File">' document.getElementById('MyFile').insertAdjacentHTML("beforeEnd",str) } </script> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> <LINK href="../StyleSheet1.css" type="text/css" rel="stylesheet"> </HEAD> <body> <form id="Form1" method="post" runat="server" enctype="multipart/form-data"> <FONT face="宋体"> <P> <uc1:pageHead id="PageHead1" runat="server"></uc1:pageHead></P> <div class="tdT"> 多文件同时上载</div> <div class="divtit" id="MyFile"><INPUT type="file" name="File" size="50"></div> <br> <DIV class="tdT"> <INPUT type="button" value="增加(Add)" onclick="addFile()"> <asp:Button id="btUp" runat="server" Text="开始上载"></asp:Button> <INPUT type="button" value="重置(ReSet)" onclick="this.form.reset()"></DIV> <DIV class="tdT"> </DIV> <DIV class="tdT"> <asp:Label id="upmessage" runat="server"></asp:Label></DIV> </FONT> </form> </body></HTML> .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;using System.Text;using System.IO;using System.Configuration;using System.Data.SqlClient;namespace Vista.Project...{ /**//// <summary> /// MultiFileUp 的摘要说明。 /// </summary> public class MultiFileUp : System.Web.UI.Page ...{ protected System.Web.UI.WebControls.Button btUp; private readonly string SQLCONNECTIONSTRING = ConfigurationSettings.AppSettings["SQLCONNECTIONSTRING"].ToString(); protected System.Web.UI.WebControls.Label upmessage; private void Page_Load(object sender, System.EventArgs e) ...{ // 在此处放置用户代码以初始化页面 } private void GetupFile(string iUrl) ...{ SqlConnection conn = new SqlConnection(SQLCONNECTIONSTRING); string strCom = "insert into UpFile (FileUrl) values ('" + iUrl +"')"; SqlCommand comm = new SqlCommand(strCom,conn); //定义访问数据库的类型为存储过程 try ...{ conn.Open();} catch (Exception ex)...{throw new Exception("数据库连接失败!",ex);} try ...{ comm.ExecuteNonQuery();} catch (Exception ex)...{throw new Exception("数据库连接失败!",ex);} } private void MultiFileUpload() ...{ HttpFileCollection fileList = HttpContext.Current.Request.Files; //存放上载文件的操作消息 StringBuilder uploadMessage = new StringBuilder("当前上载的文件分别是:<hr color=red>"); int fileIndex = 0; try ...{ for (fileIndex = 0;fileIndex < fileList.Count;fileIndex++) ...{ //获取当前上载的文件 HttpPostedFile postedFile = fileList[fileIndex]; string fileName; string fileExtension; //获取上载文件的文件名称 fileName = Path.GetFileName(postedFile.FileName); if (fileName != null) ...{ fileExtension = Path.GetExtension(fileName); uploadMessage.Append("上载的文件类型:"+ postedFile.ContentType.ToString()+"<br>"); uploadMessage.Append("客户端文件地址:" + postedFile.FileName + "<br>" ); uploadMessage.Append("上载文件的文件名:" + fileName + "<br>" ); uploadMessage.Append("上载文件的扩展名:" + fileExtension + "<br>" ); postedFile.SaveAs(MapPath("Photo/") + fileName); GetupFile(fileName); } } upmessage.Text = uploadMessage.ToString(); } catch (Exception ex) ...{ upmessage.Text = ex.Message; } } Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) ...{ // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /**//// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() ...{ this.btUp.Click += new System.EventHandler(this.btUp_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void btUp_Click(object sender, System.EventArgs e) ...{ MultiFileUpload(); } }}