C# program to get last write time of file or directory

In this C# program, we will figure out how to get last compose time of a document or an index? To get this, we are utilizing ‘GetLastWriteTime()’ strategy for ‘Record’ class.

Given a record and an index and we need to locate their last compose time utilizing C# program.


This is a technique for “Document class, it is utilized to get the last compose time of given record/index.




path – Location of record or index.

Last compose time contains the accompanying point of interest:

  • Date
  • Month
  • Year
  • Hour
  • Minute
  • Second
  • AM/PM


using System;
using System.IO;

namespace ConsoleApplication1
    class Program
        static void Main()
            DateTime dt1;
            DateTime dt2;

            dt1 = File.GetLastWriteTime("ABC.TXT");
            Console.WriteLine("Last Write Time of file(ABC.TXT) : " + dt1);

            dt2 = File.GetLastWriteTime("mydir");
            Console.WriteLine("Last Write Time of directory(mydir) : " + dt2);


Last Write Time of file(ABC.TXT) : 10/31/2017 9:38:13 PM
Last Write Time of directory(mydir) : 10/31/2017 9:08:23 PM

Note: In the above program, we have to recall, when we use “Document” class, System.IO namespace must be remembered for the program.

Leave a Comment

error: Alert: Content is protected!!