Get DirectoryInfo from FileInfo : Directory : File Directory Stream C# Examples


C# Examples » File Directory Stream » Directory »

 

Get DirectoryInfo from FileInfo









    
using  System;
using  System.IO;

class  MainClass
{
        public  static  void  Main(string[]  args)
        {
                FileInfo  file  =  new  FileInfo("c:\\test.txt");

                //  Display  directory  information.
                DirectoryInfo  dir  =  file.Directory;

                Console.WriteLine("Checking  directory:  "  +  dir.Name);
                Console.WriteLine("In  directory:  "  +  dir.Parent.Name);
                Console.Write("Directory  exists:  ");
                Console.WriteLine(dir.Exists.ToString());

        }
}
    
   
  
   



Output

Checking directory: c:\

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an ob
ject.
   at MainClass.Main(String[] args)


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo File Directory Stream
» Directory