Get File’s Last Modified or Last Written date in C#
Today in this article, we shall see how to get File’s Last Modified or Last Written date in C# application code.
Today in this article, we will cover below aspects,
Get Files last Modified date or Last Written date
DateTime modifyTime = File.GetLastWriteTime(@"file-input-thecodebuzz.txt");
Get Files created Date date
DateTime creationTime= File.GetCreationTime(@"file-input-thecodebuzz.txt");
As per Microsoft gudelines,
This method may return an inaccurate value, because it uses native functions whose values may not be continuously updated by the operating system. Each operating system manages the last write time according to its own rules. To improve performance, an operating system might not set the last write time value to the exact time of the last write operation, but might set it to a close approximation instead.
File GetLastWriteTime returns 1601
This method returns January 1, 1601 A.D. (C.E.) Coordinated Universal Time (UTC) if the specified file doesn’t exist in the specified path.
Exceptions
You can handle any of the below exceptions,
- UnauthorizedAccessException
- ArgumentException
- PathTooLongException
- NotSupportedException
References:
Do you have any comments or ideas or any better suggestions to share?
Please sound off your comments below.
Happy Coding !!
Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.