Asp.net对文件夹和文件的操作类

王朝asp·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

using System;

using System.IO;

using System.Web;

namespace SEC

{

/**//// <summary>

/// 对文件和文件夹的操作类

/// </summary>

public class FileControl

{

public FileControl()

{

}

/**//// <summary>

/// 在根目录下创建文件夹

/// </summary>

/// <param name="FolderPath">要创建的文件路径</param>

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;

}

}

}

/**//// <summary>

/// 删除一个文件夹下面的字文件夹和文件

/// </summary>

/// <param name="FolderPathName"></param>

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;

}

}

}

/**//// <summary>

/// 删除一个文件

/// </summary>

/// <param name="FilePathName"></param>

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();

[1] [2] [3] 下一页

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航