StringExtensions.GetFileExtension Method

CSharp Extensions

StringExtensionsGetFileExtension Method
Extract the extension of a file if the current string is a valid file name.

Namespace: CSharpExtensions
Assembly: CSharpExtensions (in CSharpExtensions.dll) Version: (
public static string GetFileExtension(
	this string fileName
Public Shared Function GetFileExtension ( 
	fileName As String
) As String
static String^ GetFileExtension(
	String^ fileName
static member GetFileExtension : 
        fileName : string -> string 


Type: SystemString
A string containing a valid file name.

Return Value

Type: String
Extracted file extension.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type String. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
If invalid file name is provided an empty string is returned.
See Also