Mega Code Archive

 
Categories / C# / File Stream
 

Delete a file if exist

using System.IO;   /// <summary>   /// Static methods extending the <see cref="File"/> class.   /// </summary>   public static class FileExtension   {     /// <summary>     /// Deletes the specified <paramref name="file"/> if it exists.     /// </summary>     /// <param name="file">The file to delete.</param>     public static void DeleteIfExists(string file)     {       if (File.Exists(file))       {         File.Delete(file);       }     }   }