Powered by Blogger.

Friday, February 14, 2014

Get last modified time of a file in C#.Net

In this post we will discuss how to get the last modified time of a file in C#.Net.

Also you can check my previous posts on:

- Multithreading in C#.Net

- Thread Pool class

- Lock and Monitor statement in C#.Net.

To work with files and directory, Microsoft provides System.IO namespace.

Below is the sample code that will get the last modified time of the file in C#.Net.

      string fileName = @"C:\AspDotNetHelp";
      DateTime dt = File.GetLastWriteTime(fileName);

      string modifiedTime = dt.ToString();

Similarly you can get the last file access time like below:

string fileName = @"C:\AspDotNetHelp";
DateTime dt = File.LastAccessTime(fileName);

string lastAccessTime = dt.ToString();

Also you can check how to delete a file in C#.Net and Partial class in C#.Net.