How To Get File Name Using VB.NET

This article explains how to create FileInfo.The FileInfo class provides properties to get file name, extension, directory, size and file attributes.
  • 7268

Get File Name

The FileName property returns just the file name part of the full path of a file. The following code snippet returns the file name.

Imports System.IO

Module Module1

    Sub Main()

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

        Dim fi As New IO.FileInfo(fileName)

        File.Create(fileName)

        Dim justFileName As String = fi.Name

        Console.WriteLine("File Name: {0}", justFileName)

        Console.ReadLine()

    End Sub

End Module

Output:

get file name.jpg

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.