Attention: We are retiring the ASP.NET Community Blogs. Learn more >

Checking for file extensions method

A sample method for checking image file extension which can be used for exaple to check upload file control uploaded file types:

 

Public Shared FileExt As New ArrayList

Public Shared Sub InitImageExt()

FileExt.Add(".jpeg")

FileExt.Add(".jpg")

FileExt.Add(".gif")

FileExt.Add(".png")

FileExt.Add(".bmp")

End Sub

 

Public Shared Function FileExtensions(ByVal Extension As String) As Boolean

Return FileExt.Contains(Extension.ToLower)

End Function

The function returns true or false affter we pass the file extension as argument, before that we must initialize the allowed extensions InitImageExt()

Hope it helps

No Comments