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?
How to get File Created Date and Modified Date [duplicate]
Asked Answered
You could use below code:
DateTime creation = File.GetCreationTime(@"C:\test.txt");
DateTime modification = File.GetLastWriteTime(@"C:\test.txt");
if i want to know the same thing with file bytes. how could it be? –
Wideangle
Note--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) –
Tyrontyrone
You can do that using FileInfo
class:
FileInfo fi = new FileInfo("path");
var created = fi.CreationTime;
var lastmodified = fi.LastWriteTime;
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." –
Curling
File.GetLastWriteTime
to Get last modified
File.CreationTime
to get Created time
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? –
Diaphane
The SystemIO class –
Abomb
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);
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");
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?) –
Emasculate
© 2022 - 2024 — McMap. All rights reserved.
File
class, should't be that hard: msdn.microsoft.com/en-us/library/system.io.file.aspx – Projective