C# File GetLastWriteTime

Description

File GetLastWriteTime Returns the date and time the specified file or directory was last written to.

Syntax

File.GetLastWriteTime has the following syntax.


public static DateTime GetLastWriteTime(
  string path
)

Parameters

File.GetLastWriteTime has the following parameters.

  • path - The file or directory for which to obtain write date and time information.

Returns

File.GetLastWriteTime method returns A DateTime structure set to the date and time that the specified file or directory was last written to. This value is expressed in local time.

Example

The following example demonstrates GetLastWriteTime.


/* w  ww .j a va2s.co m*/

using System;
using System.IO;

class Test 
{
    public static void Main() 
    {
      string path = @"c:\Temp\MyTest.txt";
      File.SetLastWriteTime(path, new DateTime(2014,4,3));

      DateTime dt = File.GetLastWriteTime(path);
      Console.WriteLine("The last write time for this file was {0}.", dt);
      
    }
}




















Home »
  C# Tutorial »
    System.IO »




BinaryReader
BinaryWriter
Directory
DirectoryInfo
DriveInfo
File
FileInfo
FileStream
MemoryStream
Path
StreamReader
StreamWriter
StringReader
StringWriter