C#/C Sharp – Delete file in a folder

By | April 25, 2011

Hi,

Let’s see a simple example of deleting a file in a folder using c#.

[csharp]
using System;
using System.IO;

public class MainClass
{
static void Main(string[] args)
{
FileInfo sampleFile= new FileInfo(@"c:SamplestestFile.txt");

sampleFile.Create();

sampleFile.Delete();

}
}
[/csharp]

sampleFile.Create() will create the file in the specified folder.
sampleFile.Delete() will delete the file in the specified folder.

🙂

One thought on “C#/C Sharp – Delete file in a folder

Leave a Reply

Your email address will not be published. Required fields are marked *