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?
Asked
Active
Viewed 2e+01k times
101
-
Have a look at the `File` class, should't be that hard: http://msdn.microsoft.com/en-us/library/system.io.file.aspx – Max Apr 23 '14 at 11:48
-
Google gets a lot of result if you searched it first. – Soner Gönül Apr 23 '14 at 12:02
6 Answers
180
You could use below code:
DateTime creation = File.GetCreationTime(@"C:\test.txt");
DateTime modification = File.GetLastWriteTime(@"C:\test.txt");

waitefudge
- 1,801
- 1
- 11
- 3
-
3if i want to know the same thing with file bytes. how could it be? – Zaheer Ul Hassan Oct 17 '17 at 07:50
-
6Note--if it comes back with a minimum date it's probably because the file doesn't exist/invalid path, etc. (It doesn't throw an exception) – Jeff Jul 04 '19 at 18:15
49
You can do that using FileInfo
class:
FileInfo fi = new FileInfo("path");
var created = fi.CreationTime;
var lastmodified = fi.LastWriteTime;

Selman Genç
- 100,147
- 13
- 119
- 184
-
Per the link, "If you are performing multiple operations on the same file, it can be more efficient to use FileInfo instance methods instead of the corresponding static methods of the File class, because a security check will not always be necessary." – VoteCoffee Feb 12 '20 at 18:23
9
File.GetLastWriteTime
to Get last modified
File.CreationTime
to get Created time

Sajeetharan
- 216,225
- 63
- 350
- 396
7
Use :
FileInfo fInfo = new FileInfo('FilePath');
var fFirstTime = fInfo.CreationTime;
var fLastTime = fInfo.LastWriteTime;
-
These things don't stand alone. The are part of a class. Which class? – David Heffernan Apr 23 '14 at 11:50
-
6
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);

Nagaraj S
- 13,316
- 6
- 32
- 53
4
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");

markieo
- 484
- 3
- 14
-
just remember, there is a bug going back to the 90s in NTFS - windows OS gui - that mixes the created date with the modified date (ever wonder why they never fixed it?) – MC9000 Jan 18 '22 at 00:45