在ASP.NET中实现多文件上传

来源:互联网 发布:matlab网络研讨会 编辑:程序博客网 时间:2024/06/09 13:58

一下为代码片段:


privateBooleanSaveFiles()
{
//得到File表单元素
HttpFileCollectionfiles=HttpContext.Current.Request.Files;
try
{
for(intintCount=0;intCount<files.Count;intCount++)
{

HttpPostedFilepostedFile=files[intCount];
stringfileName,fileExtension;
//获得文件名字
fileName=System.IO.Path.GetFileName(postedFile.FileName);
if(fileName!="")
{
//获得文件名扩展
fileExtension=System.IO.Path.GetExtension(fileName);
//可根据不同的扩展名字,保存文件到不同的文件夹
//注意:可能要修改你的文件夹的匿名写入权限。
postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("upFiles/")+fileName);
}
}
returntrue;
}
catch(System.ExceptionEx)
{
returnfalse;
}
}

原创粉丝点击