石家庄建站平台

十年经验 优惠价格 贴心服务

服务热线 15383239821

asp.net文件与文件夹操作类(文件删除,创建,目录删除)

发布时间:2013-10-30    来源:

下面这个文件操作类,可以删除目录并且不为空的目录哦,也可以创建文件写文件,删除文件以前递归操作目录。

using system.io;
using system.web;

namespace sec
{
    /××////
    /// 对文件和文件夹的操作类
    ///
    public class filecontrol
    {
         public filecontrol()
         {

         }
         /××////
         /// 在根目录下创建文件夹
         ///
         /// 要创建的文件路径
         public void createfolder(string folderpathname)
         {
             if(folderpathname.trim().length> 0)
             {
                 try
                 {
                      string createpath = system.web.httpcontext.current.server.mappath("http://www.cnblogs.com/images/%22+folderpathname).tostring();
                      if(!directory.exists(createpath))
                      {
                          directory.createdirectory(createpath);
                       }
                 }
                 catch
                 {
                       throw;
                  }
             }
         }

         /××////
         /// 删除一个文件夹下面的字文件夹和文件
         ///
         ///
         public void deletechildfolder(string folderpathname)
         {
              if(folderpathname.trim().length> 0)
              {
                   try
                   {
                         string createpath = system.web.httpcontext.current.server.mappath(folderpathname).tostring();
                         if(directory.exists(createpath))
                         {
                              directory.delete(createpath,true);
                         }
                   }
                   catch
                   {
                         throw;
                    }
             }
         }
         /××////
         /// 删除一个文件
         ///
         public void deletefile(string filepathname)
         {
                 try
                {
                       fileinfo delefile = new fileinfo(system.web.httpcontext.current.server.mappath(filepathname).tostring());
                       delefile.delete();
                 }
                 catch
                 {

                 }
        }
        public void createfile(string filepathname)
        {
             try
             {
                  //创建文件夹
                  string[] strpath= filepathname.split('/');
            &nbs

还没开展互联网业务? 马上开始

关注多多建站公众号
扫码加好友