

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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:\new.txt
To check the existence of the above file, use the Exists() method −
if (File.Exists(@"E:\new.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:\new.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!
- Related Questions & Answers
- How to check the Existence of a File using Java?
- How to check the permissions of a file using Python?
- MongoDB query to check the existence of multiple fields
- Check for the existence of a key in Java IdentityHashMap
- Check for the existence of a value in Java IdentityHashMap
- How to check existence of an element in android listview?
- The best way to check if a file exists using standard C/C++
- How to check existence of NaN keyword in an array JavaScript
- Check existence of an element in Java ArrayList
- How to find the file using C#?
- How to check the Date and time of Access (last modified) of a File using Java?
- How to check if the file is empty using PowerShell?
- How to check if a file exists or not using Python?
- Program to check existence of edge length limited paths in Python
- How to change the permission of a file using Python?
Advertisements