Skip to content
Loading
  • Amit Mohanty
    +1
    Hey try this
    1. if (File.Exists(yourFilePath))  
    2. {  
    3.     //file exists  
    4. }  
    5. else  
    6. {  
    7.     //file does not exists. create the file  
    8.     File.Create(yourFilePath).Dispose();  
    9. } 
    +1
  • 0
    You can use ADO.Net concepts to update database columns to YES or NO depending upon whether file exists or not
    0
  • Rajanikant Hawaldar
    0
    To check for specific files use File.Exists(path), which will return a boolean indicating wheter the file at path exists. 
    1. string curFile = @"c:\temp\test.txt";  
    2. Console.WriteLine(File.Exists(curFile) ? "File exists." : "File does not exist.");  
    For more info refer below
    https://docs.microsoft.com/en-us/dotnet/api/system.io.file.exists?view=netframework-4.8 
    0
  • YaminiKumar Boyapati
    0
    First you have to check if the path exists or not before checking file exists like below
    string path = "yourpath withoout file";
    bool pathExists = Directory.Exists(path);
    Now if the pathExists is returned true, then check for the file exists like below
    string filePath = "filepath along with file";
    bool fileExists = File.Exists(filePath);
    Also, if you want to create a Folder,
    string path = "yourpath withoout file";
    If(!Directory.Exists(path))
    {
    Directory.CreateDirectory(path);
    }
    0