An alternative solution for @PaulWilliam's asnwer
In cases when you can't use a File provider for any reasons, getting a file's last modified date can be done using the System.IO.File
static class and it's method GetLastWriteTime
or GetLastWriteTimeUtc
which returns a DateTime
obj:
DateTime lastModified = System.IO.File.GetLastWriteTimeUtc(filePath);
Note that the non-utc method, GetLastWriteTime
returns the last-modified date based on the server/filesystem time.
Other than that, and all the write-read methods, System.IO.File
also contains methods that help retrieve data as last access time, creation time etc. Not only getter methods, but setters aswell.
Docs: File Class - MS Docs
Also worth pointing out that you can use the GetAttributes
/SetAttributes
methods to work with FileAttributes
enums which are used for defining a file's status as Hidden
, Compressed
etc.
Docs: File.GetAttributes(String) Method - MS Docs and FileAttributes Enum - MS Docs