在ASP.NET中实现多文件上传
减小字体
增大字体
作者:编辑整理 来源:互联网 发布时间:2008-9-15 22:28:14
一下为代码片段:
|
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; } }
|