January 4, 2016
How to Delete a File in C#/CSharp
To delete a file in C#/CSharp, we make use of File class and its static method called Delete. It will take path of the file as parameter. Example is given below.
using System;
using System.IO;
namespace Hello_World
{
class Program
{
static void Main(string[] args)
{
string path = @"C:\Users\ADMIN\Desktop\delete.txt";
File.Delete(path);
Console.WriteLine("File Deleted!");
}
}
}
using System;
using System.IO;
namespace Hello_World
{
class Program
{
static void Main(string[] args)
{
string path = @"C:\Users\ADMIN\Desktop\delete.txt";
File.Delete(path);
Console.WriteLine("File Deleted!");
}
}
}
using System; using System.IO; namespace Hello_World { class Program { static void Main(string[] args) { string path = @"C:\Users\ADMIN\Desktop\delete.txt"; File.Delete(path); Console.WriteLine("File Deleted!"); } } }