How to Set File Creation Time in C#

GetCreationTime property of File object returns the DateTime when a file was created. The datetime includes full date and time. SetCreationTime property of File object sets the creation time of a file. The following code snippet returns the creation time of a file and displays on the console. The code also overrides the original creation time with current date and time and reads it back and displays to the console. 
  1. string textFile = @"C:\Mahesh\Data\Authors.txt";  
  2. if (File.Exists(textFile))  
  3. {  
  4. // Read oritinal file creation time  
  5. DateTime creationTime = File.GetCreationTime(textFile);  
  6. // Display creation time  
  7. Console.WriteLine(creationTime.ToString("MM/dd/yyyy HH:mm:ss"));  
  8. // Manually override previous creation time to now  
  9. File.SetCreationTime(textFile, DateTime.Now );  
  10. Console.WriteLine(File.GetCreationTime(textFile));  
  11. }  
Make sure to replace the file full path with an existing file on your system.