Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

FileInfo.Name Property

Definition

Namespace:
System.IO
Assemblies:
mscorlib.dll, System.IO.FileSystem.dll
Assemblies:
netstandard.dll, System.Runtime.dll
Assemblies:
netstandard.dll, System.IO.FileSystem.dll
Assemblies:
netstandard.dll, System.IO.FileSystem.dll, System.Runtime.dll
Assembly:
System.IO.FileSystem.dll
Assembly:
mscorlib.dll
Assembly:
netstandard.dll
Source:
FileInfo.cs
Source:
FileInfo.cs
Source:
FileInfo.cs
Source:
FileInfo.cs

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Gets the name of the file.

public:
 virtual property System::String ^ Name { System::String ^ get(); };
public override string Name { get; }
member this.Name : string
Public Overrides ReadOnly Property Name As String

Property Value

The name of the file.

Examples

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)
 Console.WriteLine(fiTemp.Name);
 }
}
//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:
//fileinfoname.exe
//fileinfoname.pdb
//newTemp.txt
Imports System.IO

Public Class NameTest
 Public Shared Sub Main()
 ' Create a reference to the current directory.
 Dim di As New DirectoryInfo(Environment.CurrentDirectory)
 ' Create an array representing the files in the current directory.
 Dim fi As FileInfo() = di.GetFiles()
 Console.WriteLine("The following files exist in the current directory:")
 ' Print out the names of the files in the current directory.
 Dim fiTemp As FileInfo
 For Each fiTemp In fi
 Console.WriteLine(fiTemp.Name)
 Next fiTemp
 End Sub
End Class
'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:
'newTemp.txt
'fileinfoname.exe
'fileinfoname.pdb
'fileinfoname.Resources.resources
'fileinfoname.vbproj.GenerateResource.Cache
'fileinfoname.xml

Remarks

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.

Applies to

See also


Feedback

Was this page helpful?