![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeBehind
=
"
WebForm1.aspx.cs
"
Inherits
=
"
ClassifyInfo.WebForm1
"
%>
<! 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 >
< script type ="text/javascript" >
function AddAttachments() {
document.getElementById( " attach " ).innerText = " 继续添加附件 " ;
// tb变量未加var在javascript中代表全局变量
tb = document.getElementById( " attachments " );
var newRow = tb.insertRow();
newRow.insertCell().innerHTML = " <input type='file' size='50' name='File' /> <input type='button' value='删除' οnclick='delFile(this.parentElement.parentElement.rowIndex)' /> " ;
}
function delFile(index) {
document.getElementById( " attachments " ).deleteRow(index);
tb.rows.length > 0 ? document.getElementById( ' attach ' ).innerText = " 继续添加附件 " : document.getElementById( " attach " ).innerText = " 添加附件 " ;
}
</ script >
</ head >
< body >
< form id ="form1" runat ="server" enctype ="multipart/form-data" method ="post" >
< div >
< table id ="attachments" ></ table >
< a id ="attach" name ="attach" href ="javascript:;" style ="font-family:宋体; font-size:9pt;" title ="如果您要发送多个附件,您只需多次点击“继续添加附件”即可, 要注意附件总量不能超过发送限制的大小" onclick ="AddAttachments()" > 添加附件 </ a >
< br />< br />< br />< br />< br />
< asp:Button ID ="btnSend" runat ="server" Text ="上传" onclick ="btnSend_Click" />
</ div >
</ form >
</ body >
</ html >
<! 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 >
< script type ="text/javascript" >
function AddAttachments() {
document.getElementById( " attach " ).innerText = " 继续添加附件 " ;
// tb变量未加var在javascript中代表全局变量
tb = document.getElementById( " attachments " );
var newRow = tb.insertRow();
newRow.insertCell().innerHTML = " <input type='file' size='50' name='File' /> <input type='button' value='删除' οnclick='delFile(this.parentElement.parentElement.rowIndex)' /> " ;
}
function delFile(index) {
document.getElementById( " attachments " ).deleteRow(index);
tb.rows.length > 0 ? document.getElementById( ' attach ' ).innerText = " 继续添加附件 " : document.getElementById( " attach " ).innerText = " 添加附件 " ;
}
</ script >
</ head >
< body >
< form id ="form1" runat ="server" enctype ="multipart/form-data" method ="post" >
< div >
< table id ="attachments" ></ table >
< a id ="attach" name ="attach" href ="javascript:;" style ="font-family:宋体; font-size:9pt;" title ="如果您要发送多个附件,您只需多次点击“继续添加附件”即可, 要注意附件总量不能超过发送限制的大小" onclick ="AddAttachments()" > 添加附件 </ a >
< br />< br />< br />< br />< br />
< asp:Button ID ="btnSend" runat ="server" Text ="上传" onclick ="btnSend_Click" />
</ div >
</ form >
</ body >
</ html >
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
protected
void
btnSend_Click(
object
sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
int attCount = 0 ;
string filePath = "" ;
for ( int i = 0 ; i < Request.Files.Count; i ++ )
{
if (Request.Files[i].ContentLength > 0 )
{
filePath = Request.Files[i].FileName;
sb.Append( " Files " + ++attCount + " : " + filePath + " <br> " );
Request.Files[ 0 ].SaveAs(Server.MapPath( " ./ " ) + filePath.Substring(filePath.LastIndexOf( " \\ " ) + 1 ));
}
}
sb.Insert( 0 , " you upload " + attCount + " files.<br> " );
Response.Write(sb.ToString());
}
{
StringBuilder sb = new StringBuilder();
int attCount = 0 ;
string filePath = "" ;
for ( int i = 0 ; i < Request.Files.Count; i ++ )
{
if (Request.Files[i].ContentLength > 0 )
{
filePath = Request.Files[i].FileName;
sb.Append( " Files " + ++attCount + " : " + filePath + " <br> " );
Request.Files[ 0 ].SaveAs(Server.MapPath( " ./ " ) + filePath.Substring(filePath.LastIndexOf( " \\ " ) + 1 ));
}
}
sb.Insert( 0 , " you upload " + attCount + " files.<br> " );
Response.Write(sb.ToString());
}
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
<
system.web
>
< httpRuntime maxRequestLength ="10240" executionTimeout ="45" useFullyQualifiedRedirectUrl ="true" />
<!--
maxRequestLength:指定输入流缓冲阈值限制(以 KB 为单位),最大上传文件大小
executionTimeout:指定在被 ASP.NET 自动关闭前,允许执行请求的最大秒数。
useFullyQualifiedRedirectUrl:指定客户端重定向是否是完全限定的(采用 "http://server/path" 形式,这是某些移动控件所必需的)
-->
</ system.web >
< httpRuntime maxRequestLength ="10240" executionTimeout ="45" useFullyQualifiedRedirectUrl ="true" />
<!--
maxRequestLength:指定输入流缓冲阈值限制(以 KB 为单位),最大上传文件大小
executionTimeout:指定在被 ASP.NET 自动关闭前,允许执行请求的最大秒数。
useFullyQualifiedRedirectUrl:指定客户端重定向是否是完全限定的(采用 "http://server/path" 形式,这是某些移动控件所必需的)
-->
</ system.web >