Windows apps
Collapse the table of content
Expand the table of content
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.Name Property

Gets the name of this DirectoryInfo instance.

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

public override string Name { get; }
/** @property */
public String get_Name ()

public override function get Name () : String

Not applicable.

Property Value

The directory name.

This Name property returns only the name of the directory, such as "Bin". To get the full path, such as "c:\public\Bin", use the FullName property.

The Name property of a DirectoryInfo requires no permission (beyond the read permission to the directory necessary to construct the Exists) but can give out the directory name. If it is necessary to hand out a DirectoryInfo to a protected directory with a cryptographically secure name, create a dummy directory for the untrusted code’s use.

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

The following example displays the name of the current DirectoryInfo instance only.

using System;
using System.IO;

class GetAName
{
    public static void Main(string[] args)
    {
        DirectoryInfo dir = new DirectoryInfo(".");
        String dirName=dir.Name;
        Console.WriteLine("DirectoryInfo name is {0}.", dirName);
    }
}

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

class GetAName
{
    public static void main(String[] args)
    {
        DirectoryInfo dir = new DirectoryInfo(".");
        String dirName = dir.get_Name();
        Console.WriteLine("DirectoryInfo name is {0}.", dirName);
    } //main
} //GetAName

import System;
import System.IO;
var dir : DirectoryInfo = new DirectoryInfo(".");
var dirName : String = dir.Name;
Console.WriteLine("DirectoryInfo name is {0}.", dirName);

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

Community Additions

Show:
© 2017 Microsoft