How do I check if a file is exists?

Category: System.IO, viewed: 377 time(s).
using System;
using System.IO;

namespace Kodecsharp.Example.System.IO {
    class FileExistsDemo {
        public static void Main(string[] args) {
            string fileName = @"c:\users\wsaryada\demo.txt";

            //
            // The File.Exists() method check to see if a file on the
            // specified path exists or not.
            //
            if (File.Exists(fileName)) {
                Console.WriteLine(fileName + " found.");
            } else {
                Console.WriteLine("Could not locate " + fileName);
            }

            Console.ReadLine();
        }
    }
}
Download Hundreds of Complimentary Industry Resources

Get hundreds of popular Industry magazines, white papers, webinars, podcasts, and more; all available at no cost to you. With more than 600 complimentary offers, you'll find plenty of titles to suit your professional interests and needs. Click Here and Sign up today!

Our Friends

Statistics

Locations of visitors to this page