Create and Delete text Files
How can I write code that delete a specific file? I have achieved this before in Visual Basic. But currently am working on a project that I need it to be able to create .txt files and delete then when exiting the application. Please note that when it comes to C# am an absolute beginner.

Pankaj Kumar ChoudharyPosted Jun 4, 2015, 8:11 PM
Manoj BhoirPosted Jun 4, 2015, 1:31 PM
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.FormClosing += new FormClosingEventHandler(Form1_Closing);
using (System.IO.FileStream fs = System.IO.File.Create("C:\\Test.txt"))
{
Byte[] info = new UTF8Encoding(true).GetBytes("This is some text in the file.");
// Add some information to the file.
fs.Write(info, 0, info.Length);
}
}
{
System.IO.File.Delete("C:\\Test.txt");
}