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

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.

The following table lists examples of other typical or related I/O tasks.

To do this...

See the example in this topic...

Create a text file.

How to: Write Text to a File

Write to a text file.

How to: Write Text to a File

Read from a text file.

How to: Read Text from a File

Retrieve a file extension.

Path.GetExtension

Retrieve the fully qualified path of a file.

Path.GetFullPath

Change the extension of a file.

Path.ChangeExtension

Retrieve only the file name from a path.

Path.GetFileNameWithoutExtension

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 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

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

Community Additions

Show:
© 2014 Microsoft