C# File Exists

C# File Exists

C# file Exists

A very simple and very useful static method File.Exists
determines whether the file exists at specified path or not.
It is provided in System.IO namespace


Many times we require to check existence of file before user upload it on server via
web interface or applications. To avoid overwriting or modifying existing files it’s
better to check the existence of file with same name in specified directory.


using System;
using System.IO;

namespace ConsoleAppication
    class Program
        static void Main()

             if( File.Exists(@"c:\SQLManagementStudio_x86_ENU.exe"))
                 Console.Write("The file exixts");    
                 Console.WriteLine("The file doesnot exists");

Output: The file exixts

 The File.Exists method accepts fully qualified path of the file as string type a parameter.
If file exists it returns Boolean true and if file doesn't exists it returns Boolean false.
The File.Exists method shold not be used for path validation.
Passing invalid path to Exists method returns false.

The File.Exists method should not be used for path validation.
Passing invalid path to Exists method returns false vale.


C# Delete All Files In DirectoryAsp.net delete file file on Server C#.net and VB.net codeC# Get File SizeASP.net File HandlingC# Read File Line By LineRead Text File in (C#.net or VB.net)Asp.net File Upload(c#) write to text fileC#-move files from foldersC# File.ReadLines() .net 4.0C# Read CSV File


My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.

I'm Satalaj.