
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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
- Related Articles
- C program to delete a file
- Golang program to delete a file
- How to delete a temporary file in Java?
- How do I delete a file in Python?
- How to delete a file using Python?
- Delete the file or directory in Java
- How to delete a string inside a file(.txt) in java?
- Java program to delete certain text from a file
- Delete file or directory on termination in Java
- How to Empty or Delete a Large File Content in Linux?
- How to Delete Specific Line from a Text File in Python?
- How to delete a file from the public folder in Laravel?
- Java Program to delete file or directory
- Java program to delete duplicate lines in text file
- Java Program to delete a file or directory when the program ends

Advertisements