Windows Dev Center

Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DirectoryInfo.Root Property

Gets the root portion of the directory.

Namespace:  System.IO
Assembly:  mscorlib (in mscorlib.dll)

public DirectoryInfo Root { get; }

Property Value

Type: System.IO.DirectoryInfo
An object that represents the root of the directory.

ExceptionCondition
SecurityException

The caller does not have the required permission.

The following example displays root locations for specified directories.

using System;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            DirectoryInfo di1 = new DirectoryInfo(@"\\tempshare\tempdir");
            DirectoryInfo di2 = new DirectoryInfo("tempdir");
            DirectoryInfo di3 = new DirectoryInfo(@"x:\tempdir");
            DirectoryInfo di4 = new DirectoryInfo(@"c:\");

            Console.WriteLine("The root path of '{0}' is '{1}'", di1.FullName, di1.Root);
            Console.WriteLine("The root path of '{0}' is '{1}'", di2.FullName, di2.Root);
            Console.WriteLine("The root path of '{0}' is '{1}'", di3.FullName, di3.Root);
            Console.WriteLine("The root path of '{0}' is '{1}'", di4.FullName, di4.Root);
        }
    }
}
/* 
This code produces output similar to the following:

The root path of '\\tempshare\tempdir' is '\\tempshare\tempdir'
The root path of 'c:\Projects\ConsoleApplication1\ConsoleApplication1\bin\Debug\tempdir' is 'c:\'
The root path of 'x:\tempdir' is 'x:\'
The root path of 'c:\' is 'c:\'
Press any key to continue . . .

*/

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8

Show:
© 2015 Microsoft