find the creation date of a file in csharp

To find the creation date of a file in C#, you can use the FileInfo class from the System.IO namespace. This class provides a property called "CreationTime" which returns a DateTime object that represents the creation time of the file.

Here's an example code snippet which demonstrates how to find the creation date of a file using the FileInfo class:

main.cs
using System.IO;

// ...

string filePath = @"C:\example\file.txt";
var fileInfo = new FileInfo(filePath);

DateTime creationTime = fileInfo.CreationTime;

Console.WriteLine($"The creation time of the file '{filePath}' is {creationTime}");
240 chars
11 lines

In this example, we first create a new instance of the FileInfo class by passing the path of the file to its constructor. We then access the "CreationTime" property of the FileInfo object to retrieve the creation date and time of the file.

Finally, we output the creation time to the Console using the WriteLine method.

gistlibby LogSnag