System.IO.Path.HasExtension Method

Determines whether a path includes a file name extension.

Syntax

public static bool HasExtension (string path)

Parameters

path
The path to search for an extension.

Returns

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.

Exceptions

TypeReason
ArgumentException path contains one or more implementation-specific invalid characters.

Remarks

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 Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar, or Path.VolumeSeparatorChar character is encountered, this method returns true.

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

Requirements

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0