71

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.)

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
Gold
  • 60,526
  • 100
  • 215
  • 315

3 Answers3

94

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

Lee Taylor
  • 7,761
  • 16
  • 33
  • 49
Steve Guidi
  • 19,700
  • 9
  • 74
  • 90
  • 15
    You can also use File.GetLastWriteTime and File.GetLastWriteTimeUTC – Jeff Yates Jul 26 '09 at 20:04
  • thank's for the answer, but it give me always the today date and time, whay ? – Gold Jul 27 '09 at 05: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? – Steve Guidi Jul 27 '09 at 13:41
  • Copying a file does not change date modified in my case. Windows 7 – Lzh Apr 20 '15 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](https://learn.microsoft.com/en-us/dotnet/api/system.io.file.getlastwritetime?view=netframework-4.7.1) – Mike Strother Apr 27 '18 at 15:20
33
string strFilePath = @"C:\myfile.txt";
DateTime lastModified = System.IO.File.GetLastWriteTime(strFilePath);

Reference: File.GetLastWriteTime on MSDN.

vapcguy
  • 7,097
  • 1
  • 56
  • 52
8

Try This.

FileInfo fileInfo = new FileInfo("path");
var created = fileInfo.CreationTime; //File Creation
var lastmodified = fileInfo.LastWriteTime;//File Modification
Community
  • 1
  • 1
raghu sathvara
  • 196
  • 1
  • 4