How can you determine the creation time or last modified time of a file?
Ask by ICSM Computer
Updated 07 May 2025
In C#, you can determine the creation time, last modified time, and last access time of a file using the
File.GetCreationTime,File.GetLastWriteTime, andFile.GetLastAccessTimemethods from theSystem.IOnamespace.Example: Get file timestamps
UTC versions (for consistency across time zones)
File.GetCreationTimeUtc(filePath)File.GetLastWriteTimeUtc(filePath)File.GetLastAccessTimeUtc(filePath)You can also set these times using:
File.SetCreationTime(filePath, DateTime.Now)File.SetLastWriteTime(...)File.SetLastAccessTime(...)Lists timestamps for all files in a folder?
C# example that lists the creation time, last modified time, and last accessed time for all files in a directory:
Optional: Recursively include subfolders
Replace:
With:
This way, you get file timestamps for all files including subdirectories.