File exists in C#

C# Code to check if file exists or not

A simple C# program to check if a file exists. For this, use the File.Exists() method in C#. This allows us to check for both the current directory and a particular directory like C: D: E: etc.

  • Current Directory
    File.Exists(“new.txt”)
  • Particular Directory
    File.Exists(@”E:\demo.txt”)

Let us see the code to check if the file exists in C#. Consider, we have a file “new.txt” in the current directory:

The output is as follows:

Above, we have used the File.Exists() method to check for the existence of a file. The output displays that we have “new.txt” in the current directory.

To understand the code correctly, let us now see the following video:

8 Best and Essential WordPress Security Plugins
5 Best WordPress Email Subscription Plugins to Help Build Email List
Studyopedia Editorial Staff
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading