You know, development projects in addition to the data access layer is very important, is common, here provides a powerful and practical tools.
C # Public helper class convert help class
C # Public helper Class Image helper class
Using system;using system.configuration;using system.collections.generic;using system.text;using System.Web;using System.web.ui;using system.web.ui.htmlcontrols;using system.web.ui.webcontrols;using System.web.ui.webcontrols.webparts;using system.web.security;using system.io;using System.IO.Compression;using System.xml;using system.diagnostics;using system.windows.forms;using system.threading;namespace Utils{Public Partial class Files {#region Delete all files and subdirectories for the specified directory////<summary>//delete all files and subdirectories for the specified directory//// lt;/summary>//<param name= "TargetDir" > Operating directory </param>//<param name= "Delsubdir" > If TR UE, which contains the operations of the subdirectory </param> public static void Deletedirectoryfiles (string TargetDir, bool Delsubdir) { foreach (String filename in Directory.GetFiles (TargetDir)) {file.setattributes (FileName, Fileattributes.normal); File.delete (FileName); } if(Delsubdir) {DirectoryInfo dir = new DirectoryInfo (TargetDir); foreach (DirectoryInfo subdi in dir. GetDirectories ()) {Deletedirectoryfiles (Subdi.fullname, true); Subdi.delete (); }}} #endregion #region Delete the specified file in the specified directory////<summary>//Delete the specified file under the specified directory </summary>//<param name= "Targetfiledir" > directory of specified files </param> public static void De Letefiles (String targetfiledir) {file.delete (targetfiledir); #endregion #region Create the specified directory///<summary>//Create the specified directory///</summary> <param name= "TargetDir" ></param> public static void CreateDirectory (string targetDir) { DirectoryInfo dir = new DirectoryInfo (TargetDir); if (!dir. Exists) dir. Create (); } #endreGion #region Create subdirectories///<summary>//Create subdirectories///</summary>//<param Nam E= "Parentdir" > Directory path </param>//<param name= "Subdirname" > subdirectory name </param> public static Voi D createdirectory (String Parentdir, String subdirname) {createdirectory (Parentdir + Path_split_char + s) Ubdirname); #endregion #region Rename folder directory///<summary>//Rename folder///</summary> <param name= "Oldflodername" > Original path folder name </param>//<param name= "Newflodername" > New path folder name </p aram>//<returns></returns> public static bool Renamefloder (string oldflodername, String Ne Wflodername) {try {if (Directory.Exists (HttpContext.Current.Server.MapPath (" ") + Oldflodername) {Directory.move (HttpContext.Current.Server.MapPath ("//") + OLDFL OdernAme, HttpContext.Current.Server.MapPath ("//") + Newflodername); } return true; } catch {return false; }} #endregion #region Delete the specified directory///<summary>//delete the specified directory//</SUMMARY> ; <param name= "TargetDir" > directory path </param> public static void DeleteDirectory (string targetDir) { DirectoryInfo dirinfo = new DirectoryInfo (TargetDir); if (dirinfo.exists) {deletedirectoryfiles (TargetDir, true); Dirinfo.delete (TRUE); }} #endregion #region detect if the directory exists///<summary>///detection directory exists///</summar y>//<param name= "strpath" > Paths </param>//<returns></returns> public STA TIC bool Directoryisexists (string strpath) {DirectoryInfo dirinfo = new DirectoryInfo (strpath); return dirinfo.exists; }///<summary>///detection directory exists///</summary>//<param name= "strpath" > Path < /param>//<param name= "create" > if not present, create </param> public static void Directoryisexists (Stri Ng strpath, bool Create) {DirectoryInfo dirinfo = new DirectoryInfo (strpath); return dirinfo.exists; if (!dirinfo.exists) {if (Create) dirinfo.create (); }} #endregion #region Delete all subdirectories of the specified directory, excluding deletion of the current directory file///<summary>//Delete all subdirectories of the specified directory. Does not include deletion of the current directory file///</summary>//<param name= "TargetDir" > directory path </param> public static void Deletesubdirectory (String targetDir) {foreach (String subdir in Directory.getdirectories (targetdi R) {deletedirectory (subdir); }} #endregion #region Copy all files from the specified directory////<summary>//Copy all files of the specified directory////</summary>//<param Name= "SourceDir" > Original directory </param>//<param name= "TargetDir" > Target directory </param>//<param N Ame= "OverWrite" > If true, overwrite files with the same name, otherwise do not overwrite </param>//<param name= "Copysubdir" > If True, contains directory, otherwise does not contain </ param> public static void CopyFiles (String sourcedir, String targetDir, bool OverWrite, BOOL Copysubdir) {//Copy current directory file foreach (String sourcefilename in Directory.GetFiles (SourceDir)) { String targetfilename = Path.Combine (TargetDir, Sourcefilename.substring (Sourcefilename.lastindexof (PATH_SPLIT_ CHAR) + 1); if (file.exists (TargetFileName)) {if (OverWrite = = True) { File.setattributes (TargetFileName, fileattributes.normal); File.Copy (sourceFileName, TargEtfilename, OverWrite); }} else {file.copy (sourceFileName, TargetFileName, Overw rite); }}} #endregion #region move all files in the specified directory////<summary>//Move all files in the specified directory </summary>//<param name= "SourceDir" > Original directory </param>//<param name= "TargetDir" > Target directory </param>//<param name= "OverWrite" > If True to overwrite files with the same name, do not overwrite </param>//<param NA Me= "Movesubdir" > If True, contains a directory, otherwise does not contain </param> public static void MoveFiles (String sourcedir, String TargetDir , BOOL OverWrite, bool Movesubdir) {//Move current directory file foreach (String sourcefilename in DIRECTORY.G Etfiles (SourceDir)) {String targetfilename = Path.Combine (TargetDir, sourcefilename.substring (s Ourcefilename.lastindexof (Path_split_char) + 1)); if (File.exists (TargetFileName)) {if (OverWrite = = True) {Fi Le. SetAttributes (TargetFileName, fileattributes.normal); File.delete (TargetFileName); File.move (sourceFileName, TargetFileName); }} else {File.move (sourcefilename, TargetFileName); }} if (Movesubdir) {foreach (String sourcesubdir in Director Y.getdirectories (SourceDir)) {string targetsubdir = Path.Combine (TargetDir, Sourcesubdi R.substring (Sourcesubdir.lastindexof (Path_split_char) + 1)); if (! Directory.Exists (Targetsubdir)) directory.createdirectory (Targetsubdir); MoveFiles (Sourcesubdir, Targetsubdir, OverWrite, true); Directory.delete (Sourcesubdir); }}} #endregion}}
The C # Public help class Directory Help class