How to Get Create Date and Update Date of File in C#

Hi Programmers, welcome to new post of This article i’ll write the codes to get file create date and file update date using c# console application. if any changes occur in files we can easily tract by using FileInfo class and DateTime Structure. Let’s see the Codes. If file invalid or doesn’t exists then it return Microsoft windows time start at 1601-01-01. See below image.

Example of File Create and Update Date . See below image.

Directly use below codes into Editor.

using System;
using System.IO;

namespace ConsoleApp7
    class Program
        static void Main(string[] args)
            string str = @"C:\Users\Adam\Desktop\xyz.xml";
            FileInfo fi = new FileInfo(str);

            DateTime d1 = fi.CreationTime, d2 = fi.LastWriteTime, d3 = fi.LastAccessTime;
            Console.WriteLine("Creation time: {0},\nLast access time: {1}," +
                                "\nLast write time: {2} \n", d1, d2, d3);

Happy Coding…Thanks.

Post Author: adama