Powered by Blogger.

Tuesday, September 24, 2013

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 and 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.