1if (File.Exists(@"D:\myfile.txt")) {
2 Console.WriteLine("The file exists.");
3}
1using System;
2using System.IO;
3
4public class Example
5{
6 public static void Main()
7 {
8 string path = @"C:\path\to\some\dir";
9 string filename = "somefile.ext";
10
11 if (File.Exists(path + @"\" + filename))
12 {
13 Console.WriteLine("File found in the specified directory!");
14 }
15 else
16 {
17 Console.WriteLine("File does not exist in the specified directory!");
18 }
19 }
20}