menggunakan Sistem;
menggunakan Sistem.IO;
menggunakan Sistem.Web;
ruang nama SEC
{
/**//// <ringkasan>
/// 对文件和文件夹的操作类
/// </ringkasan>
FileControl kelas publik
{
Kontrol File publik()
{
}
/**//// <ringkasan>
/// 在根目录下创建文件夹
/// </ringkasan>
/// <param name="FolderPath">要创建的文件路径</param>
kekosongan publik BuatFolder(string Nama FolderPath)
{
if(FolderPathName.Trim().Panjang>0)
{
mencoba
{
string CreatePath = System.Web.HttpContext.Current.Server.MapPath
("../../../Images/"+FolderPathName).ToString();
if(!Directory.Exists(CreatePath))
{
Direktori.CreateDirectory(CreatePath);
}
}
menangkap
{
melemparkan;
}
}
}
/**//// <ringkasan>
/// 删除一个文件夹下面的字文件夹和文件
/// </ringkasan>
/// <param nama="FolderPathName"></param>
kekosongan publik DeleteChildFolder (string Nama FolderPath)
{
if(FolderPathName.Trim().Panjang>0)
{
mencoba
{
string CreatePath = Sistem.Web.HttpContext.Current.Server.MapPath
(FolderPathName).ToString();
if(Direktori.Ada(CreatePath))
{
Direktori.Hapus(CreatePath,true);
}
}
menangkap
{
melemparkan;
}
}
}
/**//// <ringkasan>
/// 删除一个文件
/// </ringkasan>
/// <param nama="FilePathName"></param>
kekosongan publik DeleteFile (string NamaJalur File)
{
mencoba
{
FileInfo DeleFile = FileInfo baru(System.Web.HttpContext.Current.Server.MapPath
(FilePathName).ToString());
HapusFile.Hapus();
}
menangkap
{
}
}
kekosongan publik CreateFile(string FilePathName)
{
mencoba
{
//创建文件夹
string[] strPath= NamaPathFile.Split('/');
CreateFolder(FilePathName.Replace("/" + strPath[strPath.Length-1].ToString(),"")); //创建文件
夹
FileInfo CreateFile = FileInfo baru (System.Web.HttpContext.Current.Server.MapPath
(FilePathName).ToString()); //创建文件
if(!CreateFile.Exists)
{
FileStream FS=BuatFile.Buat();
FS.Tutup();
}
}
menangkap
{
}
}
/**//// <ringkasan>
/// 删除整个文件夹及其字文件夹和文件
/// </ringkasan>
/// <param nama="FolderPathName"></param>
kekosongan publik DeleParentFolder (string Nama FolderPath)
{
mencoba
{
DirectoryInfo DelFolder = DirectoryInfo baru(System.Web.HttpContext.Current.Server.MapPath
(FolderPathName).ToString());
if(DelFolder.Ada)
{
DelFolder.Hapus();
}
}
menangkap
{
}
}
/**//// <ringkasan>
/// 在文件里追加内容
/// </ringkasan>
/// <param nama="FilePathName"></param>
public void ReWriteReadinnerText(string FilePathName,string WriteWord)
{
mencoba
{
//建立文件夹和文件
//BuatFolder(NamaJalur File);
BuatFile(NamaJalur File);
//得到原来文件的内容
FileStream FileRead=FileStream baru(System.Web.HttpContext.Current.Server.MapPath
(FilePathName).ToString(),FileMode.Open,FileAccess.ReadWrite);
StreamReader FileReadWord=StreamingReader baru(FileRead,System.Text.Encoding.Default);
string OldString = FileReadWord.ReadToEnd().ToString();
OldString = OldString + Kata Tulis;
//把新的内容重新写入
StreamWriter FileWrite=StreamingWriter baru(FileRead,System.Text.Encoding.Default);
FileWrite.Write(WriteWord);
//关闭
FileWrite.Tutup();
FileReadWord.Tutup();
FileRead.Tutup();
}
menangkap
{
// melemparkan;
}
}
/**//// <ringkasan>
/// 在文件里追加内容
/// </ringkasan>
/// <param nama="FilePathName"></param>
string publik ReaderFileData (string FilePathName)
{
mencoba
{
FileStream FileRead=FileStream baru(System.Web.HttpContext.Current.Server.MapPath
(FilePathName).ToString(),FileMode.Open,FileAccess.Read);
StreamReader FileReadWord=StreamingReader baru(FileRead,System.Text.Encoding.Default);
string TxtString = FileReadWord.ReadToEnd().ToString();
//关闭
FileReadWord.Tutup();
FileRead.Tutup();
kembalikan TxtString;
}
menangkap
{
melemparkan;
}
}
/**//// <ringkasan>
/// 读取文件夹的文件
/// </ringkasan>
/// <param nama="FilePathName"></param>
/// <pengembalian></pengembalian>
DirectoryInfo publik checkValidSessionPath(string FilePathName)
{
mencoba
{
DirectoryInfo MainDir = DirectoryInfo baru(System.Web.HttpContext.Current.Server.MapPath
(FilePathName));
kembalikan MainDir;
}
menangkap
{
melemparkan;
}
}
}
}