using System; 
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

("../../../Images/"+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('/'); 
CreateFolder(FilePathName.Replace("/" + strPath[strPath.Length-1].ToString(),"")); //创建文件

夹 
FileInfo CreateFile =new FileInfo(System.Web.HttpContext.Current.Server.MapPath

(FilePathName).ToString()); //创建文件 
if(!CreateFile.Exists) 

FileStream FS=CreateFile.Create(); 
FS.Close(); 


catch 



/**//// 
/// 删除整个文件夹及其字文件夹和文件 
/// 
/// 
public void DeleParentFolder(string FolderPathName) 

try 

DirectoryInfo DelFolder = new DirectoryInfo(System.Web.HttpContext.Current.Server.MapPath

(FolderPathName).ToString()); 
if(DelFolder.Exists) 

DelFolder.Delete(); 


catch 



/**//// 
/// 在文件里追加内容 
/// 
/// 
public void ReWriteReadinnerText(string FilePathName,string WriteWord) 

try 

//建立文件夹和文件 
//CreateFolder(FilePathName); 
CreateFile(FilePathName); 
//得到原来文件的内容 
FileStream FileRead=new FileStream(System.Web.HttpContext.Current.Server.MapPath

(FilePathName).ToString(),FileMode.Open,FileAccess.ReadWrite); 
StreamReader FileReadWord=new StreamReader(FileRead,System.Text.Encoding.Default); 
string OldString = FileReadWord.ReadToEnd().ToString(); 
OldString = OldString + WriteWord; 
//把新的内容重新写入 
StreamWriter FileWrite=new StreamWriter(FileRead,System.Text.Encoding.Default); 
FileWrite.Write(WriteWord); 
//关闭 
FileWrite.Close(); 
FileReadWord.Close(); 
FileRead.Close(); 

catch 

// throw; 

}

/**//// 
/// 在文件里追加内容 
/// 
/// 
public string ReaderFileData(string FilePathName) 

try 
{

FileStream FileRead=new FileStream(System.Web.HttpContext.Current.Server.MapPath

(FilePathName).ToString(),FileMode.Open,FileAccess.Read); 
StreamReader FileReadWord=new StreamReader(FileRead,System.Text.Encoding.Default); 
string TxtString = FileReadWord.ReadToEnd().ToString(); 
//关闭 
FileReadWord.Close(); 
FileRead.Close(); 
return TxtString; 

catch 

throw; 


/**//// 
/// 读取文件夹的文件 
/// 
/// 
/// 
public DirectoryInfo checkValidSessionPath(string FilePathName) 

try 

DirectoryInfo MainDir = new DirectoryInfo(System.Web.HttpContext.Current.Server.MapPath

(FilePathName)); 
return MainDir;


catch 

throw; 



 
 

Asp.net对文件夹和文件的操作类的更多相关文章

  1. asp.net 检查文件夹和文件是否存在

    原文  asp.net 检查文件夹和文件是否存在 允许 path 参数指定相对或绝对路径信息. 相对路径信息被解释为相对于当前工作目录. 检查该目录是否存在之前,从 path 参数的末尾移除尾随空格. ...

  2. MVC文件夹及文件说明

    一个典型的 ASP.NET MVC Web 应用程序的文件夹内容如下所示: 所有的 MVC 应用程序的文件夹名称都是相同的.MVC 框架是基于默认的命名.控制器写在 Controllers 文件夹中, ...

  3. 使用FileSystemWatcher监控文件夹及文件

    引言 这一周主要精力集中学习一个同事开发的本地文件搜索项目上,其中客户端添加共享文件时主要是使用FileSystemWatcher 监控文件,并在各种事件发生时向服务器发送消息. 解决方法 FileS ...

  4. Visual Studio(VS2012) Project&(Solution) 虚拟文件夹 & 物理文件夹

    今天发生个怪事:在 Solution Explorer 中,x project 内建立文件夹(folder)时,同时在磁盘目录下也创建了同名的文件夹. 1, 原本:应该只是创建一个“虚拟文件夹”用来“ ...

  5. TortoiseSVN文件夹及文件图标不显示解决方法

              由于自己的电脑是win7(64位)的,系统安装TortoiseSVN之后,其他的功能都能正常的使用,但是就是文件夹或文件夹的左下角就是不显示图标,这个问题前一段时间就遇到了(那个时 ...

  6. python 实现彻底删除文件夹和文件夹下的文件

    python 中有很多内置库可以帮忙用来删除文件夹和文件,当面对要删除多个非空文件夹,并且目录层次大于3层以上时,仅使用一种内置方法是无法达到彻底删除文件夹和文件的效果的,比较low的方式是多次调用直 ...

  7. Projects\Portal_Content\Indexer\CiFiles文件夹下文件占用磁盘空间过大问题。

    C:\Program Files\Microsoft Office Servers\12.0\Data\Office Server\Applications\9765757d-15ee-432c-94 ...

  8. android 获取文件夹、文件的大小 以B、KB、MB、GB 为单位

    android 获取文件夹.文件的大小 以B.KB.MB.GB 为单位   public class FileSizeUtil { public static final int SIZETYPE_B ...

  9. C#操作文件夹及文件的方法的使用

    本文收集了目前最为常用的C#经典操作文件的方法,具体内容如下:C#追加.拷贝.删除.移动文件.创建目录.递归删除文件夹及文件.指定文件夹下面的所有内容copy到目标文件夹下面.指定文件夹下面的所有内容 ...

随机推荐

  1. 如何选择Android自动化框架的几点拙见

    首先由于我自己也是个新手,也是在学习各种框架然后给公司项目选定相应自动化框架,研究移动自动化测试框架也就近段时间而已,所以我只能从我自己今天为止的认知角度给各个框架抒发我自己的拙见,你看是否能从中接纳 ...

  2. Django中前端界面实现级联查询

    Django前端界面实现级联查询 一.前端界面中 <span scope="col" colspan="6"> 院系:<select id=& ...

  3. Linux 的日常 tools

    Linux基础命令里的就不再赘述了. Table of Contents 一.下载(命令行工具,只给出常用的命令说明) wget/cURL(一般系统自带) aria2/axel多线程下载 1. ari ...

  4. Python之协程的实现

    1.Python里面一般用gevent实现协程协程, 而协程就是在等待的时候切换去做别的操作,相当于将一个线程分块,充分利用资源 (1)低级版协程的实现 import gevent def test1 ...

  5. 常用JS整理

    目录 1 事件 a addEventListener--绑定事件b removeEventListener--解绑事件,只能解开addEventListener绑定的事件 2 JS获取节点信息a by ...

  6. Tomcat源码分析(二)------ 一次完整请求的里里外外

    Tomcat源码分析(二)------ 一次完整请求的里里外外   前几天分析了一下Tomcat的架构和启动过程,今天开始研究它的运转机制.Tomcat最本质就是个能运行JSP/Servlet的Web ...

  7. caffe-dnnh实验

    下面是我在做基于深度哈希的大规模图像检索中的一个实验,相关文档介绍给大家,具体内容查看提供的相关链接,总结的很到位了,我就不再赘述. 实践cvpr2015年的深度哈希图像检索论文:Simultaneo ...

  8. 逆向中静态分析工具——IDA初学者笔记之字符串分析

    逆向中静态分析工具——IDA初学者笔记之字符串分析 程序中往往包含很多字符串资源,这些资源存在于PE文件的rdata段,使用IDA反编译后,可以查找到这些字符串, 逆向破解程序通常需要一个突破点,而这 ...

  9. 请大家注意这个网站www.haogongju.net

    乱转发我的文章,求职之路(拿到百度.美团.趋势科技.华为offer),不注明出处,我把原来的博客删除了,被转载的文章还在,www.haogongju.net,你侵犯版权!!!请你自动撤销!!!

  10. POJ3648 Wedding 【2-sat】

    题目 Up to thirty couples will attend a wedding feast, at which they will be seated on either side of ...