This documentation is archived and is not being maintained.

FileInfo.Name Property

Gets the name of the file.

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

public override string Name { get; }

Property Value

Type: System.String
The name of the file.

When first called, FileInfo calls Refresh and caches information about the file. On subsequent calls, you must call Refresh to get the latest copy of the information.

The name of the file includes the file extension.

The following example uses the Name property to display the names of files in the current directory.

using System;
using System.IO;

public class NameTest 
    public static void Main() 
        // Create a reference to the current directory.
        DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory);
        // Create an array representing the files in the current directory.
        FileInfo[] fi = di.GetFiles();
        Console.WriteLine("The following files exist in the current directory:");
        // Print out the names of the files in the current directory.
        foreach (FileInfo fiTemp in fi)
//This code produces output similar to the following; 
//results may vary based on the computer/file structure/etc.:
//The following files exist in the current directory:

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.