Path.HasExtension 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.

Determines whether a path includes a file name extension.

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

static member HasExtension : 
        path:string -> bool

Parameters

path
Type: System.String

The path to search for an extension.

Return Value

Type: System.Boolean

true if the characters that follow the last directory separator (\\ or /) or volume separator (:) in the path include a period (.) followed by one or more characters; otherwise, false.

Exception Condition
ArgumentException

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

Starting from the end of path, this method searches for a period (.) followed by at least one character. If this pattern is found before a DirectorySeparatorChar, AltDirectorySeparatorChar, or VolumeSeparatorChar character is encountered, this method returns true.

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

The following code example demonstrates the use of the HasExtension method.

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: