Get and set file creation, modification, and access times in C#

The File class provides methods that get and set file creation, modification, and access times. The following code shows how the example uses those methods to get and set a file's times.
// Get the file's times.
private void btnGetTimes_Click(object sender, EventArgs e)
{
txtCreationTime.Text = File.GetCreationTime(txtFile.Text).ToString();
txtModifiedTime.Text = File.GetLastWriteTime(txtFile.Text).ToString();
txtAccessTime.Text = File.GetLastAccessTime(txtFile.Text).ToString();
}

// Set the file's times.
private void btnSetTimes_Click(object sender, EventArgs e)
{
File.SetCreationTime(txtFile.Text, DateTime.Parse(txtCreationTime.Text));
File.SetLastWriteTime(txtFile.Text, DateTime.Parse(txtModifiedTime.Text));
File.SetLastAccessTime(txtFile.Text, DateTime.Parse(txtAccessTime.Text));
}

   

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.