How to get File Created Date and Modified Date

C#FileIoLast ModifiedDatecreated

C# Problem Overview


I have an .NET EXE file . I want to find the file created date and modified date in C# application. Can do it through reflection or with IO stream?

C# Solutions


Solution 1 - C#

You could use below code:

DateTime creation = File.GetCreationTime(@"C:\test.txt");
DateTime modification = File.GetLastWriteTime(@"C:\test.txt");

Solution 2 - C#

You can do that using FileInfo class:

FileInfo fi = new FileInfo("path");
var created = fi.CreationTime;
var lastmodified = fi.LastWriteTime;

Solution 3 - C#

File.GetLastWriteTime to Get last modified

File.CreationTime to get Created time

Solution 4 - C#

Use :

FileInfo fInfo = new FileInfo('FilePath');
var fFirstTime = fInfo.CreationTime;
var fLastTime = fInfo.LastWriteTime;

Solution 5 - C#

File.GetLastWriteTime Method >Returns the date and time the specified file or directory was last written to.

string path = @"c:\Temp\MyTest.txt";
DateTime dt = File.GetLastWriteTime(path);

For create time File.GetCreationTime Method

DateTime fileCreatedDate = File.GetCreationTime(@"C:\Example\MyTest.txt");
Console.WriteLine("file created: " + fileCreatedDate);

Solution 6 - C#

You can use this code to see the last modified date of a file.

DateTime dt = File.GetLastWriteTime(path);

And this code to see the creation time.

DateTime fileCreatedDate = File.GetCreationTime(@"C:\Example\MyTest.txt");

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiongriffithstrattonView Question on Stackoverflow
Solution 1 - C#waitefudgeView Answer on Stackoverflow
Solution 2 - C#Selman GençView Answer on Stackoverflow
Solution 3 - C#SajeetharanView Answer on Stackoverflow
Solution 4 - C#DotNet TeamView Answer on Stackoverflow
Solution 5 - C#Nagaraj SView Answer on Stackoverflow
Solution 6 - C#markieoView Answer on Stackoverflow