In this C# program, we will figure out how to set (characterize) last access time of a document or registry? To characterize the last access time, we are utilizing ‘SetLastAccessTime()’ technique for ‘Record’ class.
Given a record and we need to characterize its last access time utilizing C# program.
File.SetLastAccessTime()
This is a technique for “Document class, which characterizes the last access time of a record or registry.
Syntax:
File.SetLastAccessTime(path);
Parameter(s):
- path – Location of record or index.
We can set after detail of last access time:
- Date
- Month
- Year
- Hour
- Minute
- Second
- AM/PM
Program:
using System;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
DateTime dt1;
Console.WriteLine("Time before set last access time:");
dt1 = File.GetLastAccessTime("ABC.TXT");
Console.WriteLine("\tLast Access Time of file(ABC.TXT) : " + dt1);
File.SetLastAccessTime("ABC.TXT", DateTime.Now);
Console.WriteLine("Time After set last access time:");
dt1 = File.GetLastAccessTime("ABC.TXT");
Console.WriteLine("\tLast Access Time of file(ABC.TXT) : " + dt1);
}
}
}
Output:
Time before set last access time:
Last Access Time of file(ABC.TXT) : 10/31/2017 9:50:59 PM
Time After set last access time:
Last Access Time of file(ABC.TXT) : 10/31/2017 9:55:36 PM
Note: In the above program, we have to recollect, when we use “Document” class, System.IO namespace must be remembered for the program.