×

VB.Net Programs

VB.Net program to print file creation time

By Nidhi Last Updated : November 16, 2024

Getting the file's creation time in VB.Net

Here, we will use the GetCreationTime() method of the File class to get the creation time of the specified file and then print the creation time on the console screen.

Program/Source Code:

The source code to print file creation time is given below. The given program is compiled and executed successfully.

VB.Net code to get the file's creation time

'VB.Net program to print file creation time.

Imports System.IO

Module Module1
    Sub Main()
        Try
            Dim D As DateTime = File.GetCreationTime("sample.txt")
            Console.WriteLine("File Creation Time : " & D.ToString())
        Catch ex As FileNotFoundException
            Console.WriteLine("File does not exist")
        End Try
    End Sub
End Module

Output

File Creation Time : 06-01-2021 22:19:11
Press any key to continue . . .

Explanation

In the above program, we created a module Module1 that contains the Main() function. The Main() function is the entry point for the program. Here, we get the file creation time of the "sample.txt" file using GetCreationTime() method and then assigned it to the object of the DateTime class and print the creation time on the console screen.

If the specified file does not exist in the computer system then a FileNotFoundException gets generated and prints the appropriate message on the console screen.

VB.Net File Handling Programs »


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.