19

How do I read the modify date of the file in C#?

I can read the creation date of the file by using the code below:

ModifyDate = File.GetCreationTime(FilePath)
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
sanchop22
  • 2,639
  • 11
  • 41
  • 64

2 Answers2

61

File.GetLastWriteTime will do the job

Filippo Pensalfini
  • 1,704
  • 12
  • 15
  • 2
    dang, beat me by seconds – Kris May 08 '12 at 11:35
  • 1
    How is this not the accepted answer? – Chris Rogers Feb 14 '16 at 22:45
  • 4
    I know I'm late to the party and this was (basically) the right answer, but technically, `DateTime lastModified = System.IO.File.GetLastWriteTime(strFilePath);`, would be more accurate... It would've been nicer had I not had to look up how to *actually* do it, from this answer. – vapcguy Jan 30 '17 at 21:59
12

I believe you're looking for GetLastWriteTime

Kris
  • 38,503
  • 9
  • 72
  • 97