Christina
12
Q:

c# check file exists

if (File.Exists(@"D:\myfile.txt")) {
   Console.WriteLine("The file exists.");
}
12
if (File.Exists("file.exe"))
{
	//file exist
} else {
  //does not exist
}
7
using System;
using System.IO;

public class Example
{
	public static void Main()
	{
		string path = @"C:\path\to\some\dir";
		string filename = "somefile.ext";

		if (File.Exists(path + @"\" + filename))
		{
			Console.WriteLine("File found in the specified directory!");
		}
		else
		{
			Console.WriteLine("File does not exist in the specified directory!");
		}
	}
}
0

New to Communities?

Join the community