73

I make a file in PC, and I want to transfer it to a PPC (Windows Mobile).

How can I get the modified date of this file?

(I need it on Windows Mobile.)

3 Answers 3

95

FileInfo.LastWriteTime and FileInfo.LastWriteTimeUtc should register this information.

5
  • 16
    You can also use File.GetLastWriteTime and File.GetLastWriteTimeUTC
    – Jeff Yates
    Commented Jul 26, 2009 at 20:04
  • thank's for the answer, but it give me always the today date and time, whay ?
    – Gold
    Commented Jul 27, 2009 at 5:11
  • 2
    If you are reading this attribute from the file that was just created (the copy), it will have today's date/time since the copy is considered a modification. However, the source file shouldn't exhibit this behavior. Perhaps you are looking for another file attribute? Commented Jul 27, 2009 at 13:41
  • Copying a file does not change date modified in my case. Windows 7
    – Lzh
    Commented Apr 20, 2015 at 18:08
  • Microsoft Docs notes: "This method may return an inaccurate value, because it uses native functions whose values may not be continuously updated by the operating system." File.GetLastWriteTime(String) Method Commented Apr 27, 2018 at 15:20
33
string strFilePath = @"C:\myfile.txt";
DateTime lastModified = System.IO.File.GetLastWriteTime(strFilePath);

Reference: File.GetLastWriteTime on MSDN.

2
  • 1
    straight forward
    – Daniel B
    Commented Nov 15, 2018 at 0:45
  • 1
    @DanielB Thanks! I'm always about doing the easiest path!
    – vapcguy
    Commented Nov 15, 2018 at 0:46
8

Try This.

FileInfo fileInfo = new FileInfo("path");
var created = fileInfo.CreationTime; //File Creation
var lastmodified = fileInfo.LastWriteTime;//File Modification

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.