- 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
How to check the Existence of a File using C#?
Let’s say we need to find the following file −
E:
ew.txt
To check the existence of the above file, use the Exists() method −
if (File.Exists(@"E:
ew.txt")) { Console.WriteLine("File exists..."); }
Here is the complete code to check the existence of a file −
Example
using System; using System.IO; public class Demo { public static void Main() { if (File.Exists(@"E:
ew.txt")) { Console.WriteLine("File exists..."); } else { Console.WriteLine("File does not exist in the E directory!"); } } }
Output
File does not exist in the E directory!
Advertisements
To Continue Learning Please Login
Login with Google