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 a path.

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

public DirectoryInfo Root { get; }
/** @property */
public DirectoryInfo get_Root ()

public function get Root () : DirectoryInfo

Not applicable.

Property Value

A DirectoryInfo object representing the root of a path.

Exception typeCondition

SecurityException

The caller does not have the required permission.

For a list of common I/O tasks, see Common I/O Tasks.

The following example demonstrates how to determine the root location of a specified directory.

using System;
using System.IO;

public class MoveToTest 
{
    public static void Main() 
    {

        // Make a reference to a directory.
        DirectoryInfo di = new DirectoryInfo("TempDir");

        // Create the directory only if it does not already exist.
        if (di.Exists == false)
            di.Create();

        // Create a subdirectory in the directory just created.
        DirectoryInfo dis = di.CreateSubdirectory("SubDir");
        Console.WriteLine("The root path of '{0}' is '{1}'", dis.Name, dis.Root);

        // Delete the parent directory.
        di.Delete(true);
    }
}

import System.*;
import System.IO.*;

public class MoveToTest
{
    public static void main(String[] args)
    {
        // Make a reference to a directory.
        DirectoryInfo di = new DirectoryInfo("TempDir");

        // Create the directory only if it does not already exist.
        if (di.get_Exists() == false) {
            di.Create();
        }

        // Create a subdirectory in the directory just created.
        DirectoryInfo dis = di.CreateSubdirectory("SubDir");

        Console.WriteLine("The root path of '{0}' is '{1}'", 
            dis.get_Name(), dis.get_Root());

        // Delete the parent directory.
        di.Delete(true);
    } //main
} //MoveToTest

import System;
import System.IO;

public class MoveToTest {
    public static function Main() {

        // Make a reference to a directory.
        var di : DirectoryInfo = new DirectoryInfo("TempDir");

        // Create the directory only if it does not already exist.
        if (di.Exists == false)
            di.Create();

        // Create a subdirectory in the directory just created.
        var dis : DirectoryInfo = di.CreateSubdirectory("SubDir");

        Console.WriteLine("The root path of '{0}' is '{1}'", dis.Name, dis.Root);

        // Delete the parent directory.
        di.Delete(true);
    }
}
MoveToTest.Main();

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft