当前位置:系统之家 > 技术开发教程 > 详细页面

在ASP.NET中完成多文件上传

在ASP.NET中完成多文件上传

更新时间:2022-05-08 文章作者:未知 信息来源:网络 阅读次数:

  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;
   }
  }

温馨提示:喜欢本站的话,请收藏一下本站!

本类教程下载

系统下载排行