Q:

C# program to delete a text file

0

Given a file, and we have to delete it using C# program.

File.Delete()

This is a method of "File" class, it deletes the given file.

Syntax:

void File.Delete(path);

Parameter(s):

path - Filename with its location.

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program

using System;
using System.IO;

namespace ConsoleApplication1
{
	class Program
	{
		static void Main()
		{
			//method to delete file
			File.Delete("123.TXT");
			//confirmation message
			Console.WriteLine("File deleted successfully");
		}
	}
}

Output

    File deleted successfully

Note: In above program, we need to remember, when we use "File" class, System.IO namespace must be included in the program. An exception is not thrown if the specified file does not exist.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# file handling (File class) solved programs/examples

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to set attributes of specified file... >>
<< C# program to replace content of one file from oth...