Many times a C# programmer has to delete files present on the hard drive. Deleting a file in C# is very simple, since most of the functionality is already provided by .NET framework. Here is a code that first checks if a file exists at a given path and if so, then deletes the file.
/// Deletes the specified file
/// <param name="fileToDelete">File (path) to be deleted.</param>wi
/// <returns>bool value indicating whether the file was deleted.</returns>
public bool DeleteFile(string fileToDelete)
catch (Exception ex)
// Log the exception