utiliser le système ;
en utilisant System.IO ;
en utilisant System.Web ;
espace de noms SEC
{
/**//// <résumé>
/// 对文件和文件夹的操作类
/// </summary>
classe publique FileControl
{
contrôle de fichier public()
{
}
/**//// <résumé>
/// 在根目录下创建文件夹
/// </summary>
/// <param name="FolderPath">要创建的文件路径</param>
public void CreateFolder (string FolderPathName)
{
si (NomCheminDossier.Trim().Longueur>0)
{
essayer
{
string CreatePath = System.Web.HttpContext.Current.Server.MapPath
(""../../../Images/"+FolderPathName).ToString();
si(!Directory.Exists(CreatePath))
{
Répertoire.CreateDirectory(CreatePath);
}
}
attraper
{
lancer;
}
}
}
/**//// <résumé>
/// 删除一个文件夹下面的字文件夹和文件
/// </summary>
/// <param name="FolderPathName"></param>
public void DeleteChildFolder (string FolderPathName)
{
si (NomCheminDossier.Trim().Longueur>0)
{
essayer
{
chaîne CreatePath = System.Web.HttpContext.Current.Server.MapPath
(FolderPathName).ToString();
si (Répertoire. Existe (CreatePath))
{
Directory.Delete(CreatePath,true);
}
}
attraper
{
lancer;
}
}
}
/**//// <résumé>
/// 删除一个文件
/// </summary>
/// <param name="FilePathName"></param>
public void DeleteFile (chaîne FilePathName)
{
essayer
{
FileInfo DeleFile = new FileInfo(System.Web.HttpContext.Current.Server.MapPath
(FilePathName).ToString());
DeleFile.Delete();
}
attraper
{
}
}
public void CreateFile (string FilePathName)
{
essayer
{
//创建文件夹
string[] strPath= FilePathName.Split('/');
CreateFolder(FilePathName.Replace("/" + strPath[strPath.Length-1].ToString(),"")); //创建文件
夹
FileInfo CreateFile =new FileInfo(System.Web.HttpContext.Current.Server.MapPath
(FilePathName).ToString()); //创建文件
si(!CreateFile.Exists)
{
FileStream FS=CreateFile.Create();
FS.Close();
}
}
attraper
{
}
}
/**//// <résumé>
/// 删除整个文件夹及其字文件夹和文件
/// </summary>
/// <param name="FolderPathName"></param>
public void DeleParentFolder (string FolderPathName)
{
essayer
{
DirectoryInfo DelFolder = new DirectoryInfo(System.Web.HttpContext.Current.Server.MapPath
(FolderPathName).ToString());
si (DelFolder.Exists)
{
DelFolder.Delete();
}
}
attraper
{
}
}
/**//// <résumé>
/// 在文件里追加内容
/// </summary>
/// <param name="FilePathName"></param>
public void ReWriteReadinnerText (chaîne FilePathName, chaîne WriteWord)
{
essayer
{
//建立文件夹和文件
//CreateFolder(FilePathName);
CreateFile(FilePathName);
//得到原来文件的内容
FileStream FileRead=new FileStream(System.Web.HttpContext.Current.Server.MapPath
(FilePathName).ToString(),FileMode.Open,FileAccess.ReadWrite);
StreamReader FileReadWord=nouveau StreamReader(FileRead,System.Text.Encoding.Default);
string OldString = FileReadWord.ReadToEnd().ToString();
VieilleChaîne = VieilleChaîne + WriteWord ;
//把新的内容重新写入
StreamWriter FileWrite=nouveau StreamWriter(FileRead,System.Text.Encoding.Default);
FileWrite.Write(WriteWord);
//关闭
FileWrite.Close();
FileReadWord.Close();
FileRead.Close();
}
attraper
{
// lancer;
}
}
/**//// <résumé>
/// 在文件里追加内容
/// </summary>
/// <param name="FilePathName"></param>
chaîne publique ReaderFileData (string FilePathName)
{
essayer
{
FileStream FileRead=new FileStream(System.Web.HttpContext.Current.Server.MapPath
(FilePathName).ToString(),FileMode.Open,FileAccess.Read);
StreamReader FileReadWord=nouveau StreamReader(FileRead,System.Text.Encoding.Default);
chaîne TxtString = FileReadWord.ReadToEnd().ToString();
//关闭
FileReadWord.Close();
FileRead.Close();
renvoie TxtString ;
}
attraper
{
lancer;
}
}
/**//// <résumé>
/// 读取文件夹的文件
/// </summary>
/// <param name="FilePathName"></param>
/// <retours></retours>
public DirectoryInfo checkValidSessionPath (string FilePathName)
{
essayer
{
DirectoryInfo MainDir = new DirectoryInfo(System.Web.HttpContext.Current.Server.MapPath
(FilePathName));
retourner MainDir ;
}
attraper
{
lancer;
}
}
}
}