Path.GetFileName Method (String)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Returns the file name and extension of the specified path string.

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

static member GetFileName : 
        path:string -> string

Parameters

path
Type: System.String

The path string from which to obtain the file name and extension.

Return Value

Type: System.String

The characters after the last directory character in path. If the last character of path is a directory or volume separator character, this method returns String.Empty. If path is null, this method returns null.

Exception Condition
ArgumentException

path contains one or more of the invalid characters defined in GetInvalidPathChars.

The returned value is null if the file path is null.

The separator characters used to determine the start of the file name are DirectorySeparatorChar and AltDirectorySeparatorChar.

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

The following code example demonstrates the behavior of the GetFileName method on a Windows-based desktop platform.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show: