usando o sistema;
usando System.IO;
usando System.Web;
espaço para nome SEC
{
/**//// <resumo>
/// 对文件和文件夹的操作类
/// </sumário>
classe pública FileControl
{
controle de arquivo público()
{
}
/**//// <resumo>
/// 在根目录下创建文件夹
/// </sumário>
/// <param name="FolderPath">要创建的文件路径</param>
public void CreateFolder(string FolderPathName)
{
if(FolderPathName.Trim().Length>0)
{
tentar
{
string CreatePath = System.Web.HttpContext.Current.Server.MapPath
("../../../Images/"+FolderPathName).ToString();
if(!Directory.Exists(CreatePath))
{
Directory.CreateDirectory(CreatePath);
}
}
pegar
{
lançar;
}
}
}
/**//// <resumo>
/// 删除一个文件夹下面的字文件夹和文件
/// </sumário>
/// <param name="FolderPathName"></param>
public void DeleteChildFolder(string FolderPathName)
{
if(FolderPathName.Trim().Length>0)
{
tentar
{
string CreatePath = System.Web.HttpContext.Current.Server.MapPath
(FolderPathName).ToString();
if(Diretório.Exists(CreatePath))
{
Directory.Delete (CreatePath, verdadeiro);
}
}
pegar
{
lançar;
}
}
}
/**//// <resumo>
/// 删除一个文件
/// </sumário>
/// <param name="FilePathName"></param>
public void DeleteFile(string NomeCaminhoDoArquivo)
{
tentar
{
FileInfo DeleFile = new FileInfo(System.Web.HttpContext.Current.Server.MapPath
(FilePathName).ToString());
DeleFile.Delete();
}
pegar
{
}
}
public void CreateFile(string FilePathName)
{
tentar
{
//创建文件夹
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.Fechar();
}
}
pegar
{
}
}
/**//// <resumo>
/// 删除整个文件夹及其字文件夹和文件
/// </sumário>
/// <param name="FolderPathName"></param>
public void DeleParentFolder(string FolderPathName)
{
tentar
{
DirectoryInfo DelFolder = novo DirectoryInfo(System.Web.HttpContext.Current.Server.MapPath
(FolderPathName).ToString());
if(DelFolder.Exists)
{
DelFolder.Delete();
}
}
pegar
{
}
}
/**//// <resumo>
/// 在文件里追加内容
/// </sumário>
/// <param name="FilePathName"></param>
public void ReWriteReadinnerText(string FilePathName,string WriteWord)
{
tentar
{
//建立文件夹和文件
//CreateFolder(NomeCaminhoDoArquivo);
CriarArquivo(NomeCaminhoArquivo);
//得到原来文件的内容
FileStream FileRead = novo FileStream (System.Web.HttpContext.Current.Server.MapPath
(FilePathName).ToString(),FileMode.Open,FileAccess.ReadWrite);
StreamReader FileReadWord=novo StreamReader(FileRead,System.Text.Encoding.Default);
string OldString = FileReadWord.ReadToEnd().ToString();
OldString = OldString + WriteWord;
//把新的内容重新写入
StreamWriter FileWrite=novo StreamWriter(FileRead,System.Text.Encoding.Default);
ArquivoWrite.Write(WriteWord);
//关闭
ArquivoWrite.Close();
ArquivoReadWord.Close();
ArquivoRead.Close();
}
pegar
{
// lançar;
}
}
/**//// <resumo>
/// 在文件里追加内容
/// </sumário>
/// <param name="FilePathName"></param>
string pública ReaderFileData(string FilePathName)
{
tentar
{
FileStream FileRead=novo FileStream(System.Web.HttpContext.Current.Server.MapPath
(FilePathName).ToString(),FileMode.Open,FileAccess.Read);
StreamReader FileReadWord=novo StreamReader(FileRead,System.Text.Encoding.Default);
string TxtString = FileReadWord.ReadToEnd().ToString();
//关闭
ArquivoReadWord.Close();
ArquivoRead.Close();
retornar TxtString;
}
pegar
{
lançar;
}
}
/**//// <resumo>
/// 读取文件夹的文件
/// </sumário>
/// <param name="FilePathName"></param>
/// <retorna></retorna>
public DirectoryInfo checkValidSessionPath(string FilePathName)
{
tentar
{
DirectoryInfo MainDir = novo DirectoryInfo(System.Web.HttpContext.Current.Server.MapPath
(FilePathName));
retornar MainDir;
}
pegar
{
lançar;
}
}
}
}