您的位置:首页 > 编程语言 > ASP

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

2010-03-17 10:37 351 查看
private Boolean SaveFiles()
              {
               //得到File表单元素
               HttpFileCollection files = HttpContext.Current.Request.Files;
               try
               {
                for(int intCount= 0; intCount< files.Count; intCount++)
                {
               
                 HttpPostedFile postedFile = files[intCount];
                 string fileName, 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);
                 }
                }
                return true;
               }
               catch(System.Exception Ex)
               {
                return false;
               }
              }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  asp.net 扩展 string file