ASP.NET实现多文件上传
来源:互联网 发布:js获取所有下拉框 编辑:程序博客网 时间:2024/05/16 09:00
前台
<script language="javascript">
function addFileControl()
{
var str='<input type=file name=File>'
document.getElementById('FileCollection').insertAdjacentHTML("beforeEnd",str)
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="uoMoreFile" method="post" runat="server" enctype="multipart/form-data">
<asp:Label Runat="server" ID="Title"></asp:Label>
<p id="FileCollection"><input type="file" size="50" name="File"></p>
<p>
<input type="button" value="增加(File)" onclick="addFileControl()">
<asp:Button Runat="server" Text="上传" id="Upload"></asp:Button>
<input onclick="this.Form.reset()" type="button" value="重置"></p>
<p align="center"><asp:Label ID="strStatus" Runat="server" Width="500px"></asp:Label></p>
</form>
</body>
后台CS
protected System.Web.UI.WebControls.Label Title;
protected System.Web.UI.WebControls.Button Upload;
protected System.Web.UI.WebControls.Label strStatus;
private void Page_Load(object sender, System.EventArgs e)
{
Title.Text="<h3>多文件上传</h3>";
// 在此处放置用户代码以初始化页面
}
private void Upload_Click(object sender, System.EventArgs e)
{
upMorefile();
}
private void upMorefile()
{
System.Web.HttpFileCollection files=System.Web.HttpContext.Current.Request.Files;
System.Text.StringBuilder strMsg=new System.Text.StringBuilder("上传的文件信息分别为:<hr color=red>");
int fileCount;
int filecount=files.Count;
try
{
for(fileCount=0;fileCount<files.Count;fileCount++)
{
//定义访问客户端上传文件的对象
System.Web.HttpPostedFile postedFile=files[fileCount];
string fileName,fileExtension;
fileName=System.IO.Path.GetFileName(postedFile.FileName);
if(fileName!=string.Empty)
{
//取的上传文件的扩展名
fileExtension=System.IO.Path.GetExtension(fileName);
//上传的文件信息
strMsg.Append("上传文件的类型:"+postedFile.ContentType.ToString()+"<br>");
strMsg.Append("客户端文件地址:"+postedFile.FileName+"<br>");
strMsg.Append("上传文件的文件名:"+fileName+"<br>");
strMsg.Append("上传文件的扩展名"+fileExtension+"<br><hr color=red>");
//保存到指定的文件夹
postedFile.SaveAs(Server.MapPath("upedFile//")+fileName);
}
}
strStatus.Text=strMsg.ToString();
return true;
}
catch(System.Exception error)
{
strStatus.Text=error.ToString();
return false;
}
}
- ASP.NET中实现多文件上传
- ASP.NET实现多文件上传
- ASP.NET实现多文件上传
- ASP.NET 中实现多文件上传
- asp.net实现多文件上传
- 实现ASP.NET多文件上传程序代码
- 实现ASP.NET多文件上传程序代码
- ASP.NET实现多文件上传
- Asp.net实现多个文件上传
- Asp.net实现多个文件上传
- ASP.NET MVC3 实现多文件上传
- ASP.NET MVC实现多文件上传
- Asp.net实现文件上传
- ASP.NET实现文件上传
- Asp.net实现文件上传
- asp.net实现上传文件
- asp.net 实现上传文件
- ASP.NET实现文件上传
- ASP.NET直接下载一个文件,而不是在IE中打开它
- MKMapPoint成为CGPoint
- Android源码备用
- ASP.NET中文件上传下载方法集合
- Servlet程序的注册与运行
- ASP.NET实现多文件上传
- java path classpath复习和移植netbeans的code到cmd下运行
- 追根究底,剖析MFC六大关键技术
- VC的若干实用小技巧
- 对 int a=2;在内存存储的理解!
- 各种播放器代码
- 11.08.07 ~ 11.08.13
- fastcgi实现apache+php 以及安装php加速器ZendOptimizer-3.3.9
- 盛大围猎C2C叫阵淘宝