67

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
  • 9,925
  • 10
  • 45
  • 68
Gold
  • 57,486
  • 97
  • 211
  • 311

3 Answers3

94

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

Lee Taylor
  • 7,155
  • 14
  • 29
  • 44
Steve Guidi
  • 19,072
  • 8
  • 70
  • 88
  • 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 – Mzn 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://docs.microsoft.com/en-us/dotnet/api/system.io.file.getlastwritetime?view=netframework-4.7.1) – Mike Strother Apr 27 '18 at 15:20
30
string strFilePath = @"C:\myfile.txt";
DateTime lastModified = System.IO.File.GetLastWriteTime(strFilePath);

Reference: File.GetLastWriteTime on MSDN.

vapcguy
  • 6,573
  • 1
  • 50
  • 47
7

Try This.

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