Name Property

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:

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
© 2015 Microsoft