Get parent directory in CSharp

Description

The following code shows how to get parent directory.

Example


/*from  w ww  . ja v  a 2 s.  c  o m*/
using System;

class Class1
{
    static void Main(string[] args)
    {
        string path = System.IO.Directory.GetCurrentDirectory();

        GetParent(path);
    }
    static void GetParent(string path)
    {
        System.IO.DirectoryInfo directoryInfo = System.IO.Directory.GetParent(path);
        System.Console.WriteLine(directoryInfo.FullName);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    IO »




File Attribute
File Security
Directory Attribute
Directory Recursive
Binary File
Text Field
Buffered IO
Create Copy Delete Move
CSV
Drive
File System Watcher
Isolated Storage
MemoryStream
Serialize
Zip