Function to get Extension of file from file name

Posted by Virendradugar under VB.NET category on | Views : 11369

Public Shared Function GetExtension(ByVal strFileName As String) As String
Dim strDocExt() As String
Dim chArray() As Char = {"."}
If (strFileName.Length > 0) Then
strDocExt = strFileName.Split(chArray)
Return "." + strDocExt(strDocExt.Length - 1)
Return ""
End If
End Function

Comments or Responses

Posted by: Raja on: 1/13/2010 Level:Starter | Status: [Member]
Virendra, its much easier than what you have written here.

There is inbuilt function available. Write following and you are done.

string extenstion = System.IO.Path.GetExtension(fileName);

Posted by: Virendradugar on: 1/13/2010 Level:Silver | Status: [Member] [MVP]
Hi Raja,

Thanks for your response. I know it but I came to know later on.

Virendra Dugar

Login to post response