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,738
  • 21
  • 105
  • 131
sanchop22
  • 2,729
  • 12
  • 43
  • 66

2 Answers2

62

File.GetLastWriteTime will do the job

Filippo Pensalfini
  • 1,714
  • 12
  • 16
  • 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
13

I believe you're looking for GetLastWriteTime

Kris
  • 40,604
  • 9
  • 72
  • 101