How to get the last access date and time of a file using WinForms with C#

1 Answer

0 votes
namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string filePath = @"D:\data.txt";

            FileInfo fileInfo = new FileInfo(filePath);

            DateTime lastAccessTime = fileInfo.LastAccessTime;

            MessageBox.Show($"The last access time of the file is: {lastAccessTime}");
        }
    }
}




/*
run:

The last access time of the file is: 26/01/2024 17:44:59

*/

 



answered Mar 29, 2024 by avibootz
...