- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Delete a file in C#
Use File.Delete method to delete a file.
Firstly, set the path of the file you want to delete.
String myPath = @"C:\New\amit.txt";
Now, use the File.Delete method to delete the file.
File.Delete(myPath);
The following is the complete code −
Example
using System; using System.IO; public class Program { public static void Main() { String myPath = @"C:\New\amit.txt"; Console.WriteLine("Deleting File"); File.Delete(myPath); } }
Output
Deleting File
Advertisements