How to Get a File Extension Using VB.NET

In this article I describe how to get a file extension in VB.NET.
  • 2927

Get a File Extension

The Extension property returns the extension of a file. The following code snippet returns the extension of a file.

Imports System.IO

Module Module1

    Sub Main()

        Dim fileName As String = "C:\Temp\MaheshTXFI.txt"

        Dim fi As New IO.FileInfo(fileName)

        Dim extn As String = fi.Extension

        Console.WriteLine("File Extension: {0}", extn)

        Console.ReadLine()

    End Sub

End Module

Output:

getfile extension.jpg

Categories

More Articles

© 2018 DotNetHeaven. All rights reserved.