How to get information about a file in c#

To obtain information about a file, we must create a new FileInfo object by specifying the path to the file and use the FileInfo object to retrieve information about the file.

Example code:

FileInfo fi = new FileInfo(@"C:\file.txt");
 
if(fi.Exists)
{
	Console.WriteLine("Filename : {0}", fi.Name);
	Console.WriteLine("Path : {0}", fi.FullName);
}

The Exists property tells us if the file exists physically.

Share Article/Example:
  • DotNetKicks
  • DZone
  • StumbleUpon
  • Print
  • Add to favorites
  • Digg
  • del.icio.us
  • Twitter
  • Facebook
  • LinkedIn
  • Posterous
  • Slashdot

 

 
eXTReMe Tracker