·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> ASP.NET网站开发 >> 在ASP.NET中实现多文件上传

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

作者:佚名      ASP.NET网站开发编辑:admin      更新时间:2022-07-23
  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;
   }
  }