.NET Framework File Input/Output C# File.Exists()

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

using System;
using System.IO;
                
public class Program
{
    public static void Main()
    {
        string filePath = "somePath";
    
        if(File.Exists(filePath))
        {
            Console.WriteLine("Exists");
        }
        else
        {
            Console.WriteLine("Does not exist");    
        }
    }
}

Can also be used in a ternary operator.

Console.WriteLine(File.Exists(pathToFile) ? "Exists" : "Does not exist");


Got any .NET Framework Question?