asp.net
Using System;
Using System.IO;
Using System.Web;
Namespace SEC
{
/**////<summary>
Action classes for files and folders
</summary>
public class Filecontrol
{
Public Filecontrol ()
{
}
/**////<summary>
Create a folder under the root directory
</summary>
<param name= "FolderPath" > File path to create </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>
Delete the word folders and files under a folder
</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>
Delete a file
</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
{
Create a folder
String[] strpath= filepathname.split ('/');
CreateFolder (Filepathname.replace ("/" + strpath[strpath.length-1). ToString (), "")); Create a file
Clip
FileInfo CreateFile =new FileInfo (System.Web.HttpContext.Current.Server.MapPath
(Filepathname). ToString ()); Create a file
if (! createfile.exists)
{
FileStream fs=createfile.create ();
Fs. Close ();
}
}
Catch
{
}
}
/**////<summary>
Delete an entire folder and its Word folders and files
</summary>
<param name= "Folderpathname" ></param>
public void Deleparentfolder (string folderpathname)
{
Try
{
DirectoryInfo delfolder = new DirectoryInfo (System.Web.HttpContext.Current.Server.MapPath
(folderpathname). ToString ());
if (delfolder.exists)
{
Delfolder.delete ();
}
}
Catch
{
}
}
/**////<summary>
Append content to File
</summary>
<param name= "Filepathname" ></param>
public void Rewritereadinnertext (String filepathname,string writeword)
{
Try
{
Creating folders and Files
CreateFolder (filepathname);
CreateFile (filepathname);
Get the contents of the original file
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);
String oldstring = Filereadword.readtoend (). ToString ();
oldstring = oldstring + Writeword;
Re-write new content to
StreamWriter Filewrite=new StreamWriter (Fileread,system.text.encoding.default);
Filewrite.write (Writeword);
Shut down
Filewrite.close ();
Filereadword.close ();
Fileread.close ();
}
Catch
{
Throw
}
}
/**////<summary>
Append content to File
</summary>
<param name= "Filepathname" ></param>
public string Readerfiledata (string filepathname)
{
Try
{
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);
String txtstring = Filereadword.readtoend (). ToString ();
Shut down
Filereadword.close ();
Fileread.close ();
return txtstring;
}
Catch
{
Throw
}
}
/**////<summary>
Read files for a folder
</summary>
<param name= "Filepathname" ></param>
<returns></returns>
Public DirectoryInfo Checkvalidsessionpath (string filepathname)
{
Try
{
DirectoryInfo maindir = new DirectoryInfo (System.Web.HttpContext.Current.Server.MapPath
(Filepathname));
return maindir;
}
Catch
{
Throw
}
}
}
}