Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,996 questions

51,941 answers

573 users

How to check if file exists in C#

4 Answers

0 votes
using System;
using System.IO;
 
class Program
{
    static void Main() {
        if (File.Exists("d:\\data.txt")) {
            Console.WriteLine("The file: d:\\data.txt exists.");
        }
    }
}

 
 
 
/*
run:
 
The file: d:\data.txt exists.
 
*/


answered Mar 15, 2015 by avibootz
edited May 14, 2024 by avibootz
0 votes
using System;
using System.IO;
 
class Program
{
    static void Main() {
        if (File.Exists(@"d:\data.txt")) {
            Console.WriteLine("The file: d:\\data.txt exists.");
        }
    }
}

 
 
 
/*
run:
 
The file: d:\data.txt exists.
 
*/


answered Mar 15, 2015 by avibootz
edited May 14, 2024 by avibootz
0 votes
using System;
using System.IO;
 
class Program
{
    static void Main() {
        string file = @"d:\data.txt";
 
        Console.WriteLine(File.Exists(file) ? "File exists." : "File does not exist.");
    }
}

 
 
 
/*
run:
 
File exists.
 
*/


answered Mar 15, 2015 by avibootz
edited May 14, 2024 by avibootz
0 votes
using System;
using System.IO;
 
class Program
{
    static void Main() {
        var FileName = @"C:\Project\file.bin";
         
        if (File.Exists(FileName)) {
            Console.WriteLine("File Exists");
        } else {
            Console.WriteLine("File Not Exists");
        }
    }
}
 
 
 
 
 
/*
run:
 
File Not Exists
 
*/

 



answered May 14, 2024 by avibootz

Related questions

1 answer 82 views
82 views asked Jul 27, 2023 by avibootz
1 answer 98 views
2 answers 132 views
2 answers 129 views
2 answers 208 views
1 answer 135 views
135 views asked Mar 10, 2017 by avibootz
1 answer 149 views
149 views asked May 2, 2022 by avibootz
...