上传文件夹下的所有文件

因为项目的需要,要实现按目录上传文件,百度了一下

首先,文件夹本身是不能上传的,你只能在service端重建文件夹,这很好办。  
  上传图片你还要遍历文件夹,如下,里面还可以对图片格式进行限制  

  System.IO.DirectoryInfo       di       
=       new       System.IO.DirectoryInfo(Request.MapPath("./uploadfile/"));   
  
foreach       (System.IO.DirectoryInfo       di1       in       di.GetDirectories())   
  
{   
  
if       (di1.Exists)   
  
{   
  
//这里写你的上传代码   
  foreach       (System.IO.FileInfo       fi       in       di1.GetFiles())   
  
{   
  
this.globalmessage.Text       =       fi.Name.ToString();//换成你的上传代码   
  }
   
  }
   
  
else   
  
{   
  
this.globalmessage.Text       +=       "目录不存在";   
  }
   
  }
     

posted on 2007-06-29 10:38  隨風.NET  阅读(1261)  评论(1编辑  收藏  举报

导航