usando Sistema;
usando System.IO;
usando System.Web;
espacio de nombres SEC
{
/**//// <resumen>
/// 对文件和文件夹的操作类
/// </summary>
control de archivos de clase pública
{
control de archivos público()
{
}
/**//// <resumen>
/// 在根目录下创建文件夹
/// </summary>
/// <param name="FolderPath">要创建的文件路径</param>
Crear carpeta pública vacía (cadena Nombre de ruta de carpeta)
{
if(FolderPathName.Trim().Longitud>0)
{
intentar
{
cadena CreatePath = System.Web.HttpContext.Current.Server.MapPath
("../../../Images/"+FolderPathName).ToString();
if(!Directorio.Exists(CreatePath))
{
Directorio.CrearDirectorio(CrearPath);
}
}
atrapar
{
tirar;
}
}
}
/**//// <resumen>
/// 删除一个文件夹下面的字文件夹和文件
/// </summary>
/// <param nombre="NombreRutaCarpeta"></param>
public void DeleteChildFolder (cadena FolderPathName)
{
if(FolderPathName.Trim().Longitud>0)
{
intentar
{
cadena CreatePath = System.Web.HttpContext.Current.Server.MapPath
(FolderPathName).ToString();
si(Directorio.Existe(CrearRuta))
{
Directorio.Delete(CreatePath,true);
}
}
atrapar
{
tirar;
}
}
}
/**//// <resumen>
/// 删除一个文件
/// </summary>
/// <param nombre="FilePathName"></param>
public void DeleteFile (cadena FilePathName)
{
intentar
{
FileInfo DeleFile = new FileInfo(System.Web.HttpContext.Current.Server.MapPath
(FilePathName).ToString());
EliminarFile.Delete();
}
atrapar
{
}
}
CreateFile público vacío (cadena FilePathName)
{
intentar
{
//创建文件夹
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(!CrearArchivo.Existe)
{
FileStream FS=CreateFile.Create();
FS.Cerrar();
}
}
atrapar
{
}
}
/**//// <resumen>
/// 删除整个文件夹及其字文件夹和文件
/// </summary>
/// <param nombre="NombreRutaCarpeta"></param>
public void DeleParentFolder (cadena FolderPathName)
{
intentar
{
DirectoryInfo DelFolder = new DirectoryInfo(System.Web.HttpContext.Current.Server.MapPath
(FolderPathName).ToString());
si(DelFolder.Exists)
{
DelFolder.Delete();
}
}
atrapar
{
}
}
/**//// <resumen>
/// 在文件里追加内容
/// </summary>
/// <param nombre="FilePathName"></param>
public void ReWriteReadinnerText (cadena FilePathName, cadena WriteWord)
{
intentar
{
//建立文件夹和文件
//CrearCarpeta(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);
cadena OldString = FileReadWord.ReadToEnd().ToString();
Cadena antigua = Cadena antigua + Palabra de escritura;
//把新的内容重新写入
StreamWriter FileWrite=nuevo StreamWriter(FileRead,System.Text.Encoding.Default);
FileWrite.Write(WriteWord);
//关闭
FileWrite.Close();
FileReadWord.Close();
FileRead.Close();
}
atrapar
{
// tirar;
}
}
/**//// <resumen>
/// 在文件里追加内容
/// </summary>
/// <param nombre="FilePathName"></param>
cadena pública ReaderFileData (cadena FilePathName)
{
intentar
{
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);
cadena TxtString = FileReadWord.ReadToEnd().ToString();
//关闭
FileReadWord.Close();
FileRead.Close();
devolver cadena de texto;
}
atrapar
{
tirar;
}
}
/**//// <resumen>
/// 读取文件夹的文件
/// </summary>
/// <param nombre="FilePathName"></param>
/// <devoluciones></devoluciones>
public DirectoryInfo checkValidSessionPath (cadena FilePathName)
{
intentar
{
DirectoryInfo MainDir = new DirectoryInfo(System.Web.HttpContext.Current.Server.MapPath
(FilePathName));
devolver DirectorioPrincipal;
}
atrapar
{
tirar;
}
}
}
}