How to gets the last time a file was written to in C#

2 Answers

0 votes
using System;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string file = @"d:\data.txt";

            try
            {
                DateTime d = File.GetLastWriteTime(file);
                Console.WriteLine(d);
            }
            catch (IOException ioex)
            {
                Console.WriteLine(ioex.Message);
            }
        }
    }
}

/*
run:
   
3/12/2015 10:53:04 AM

*/


answered Mar 17, 2015 by avibootz
0 votes
using System;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string file = @"d:\data.txt";

            try
            {
                DateTime d = File.GetLastWriteTimeUtc(file); // universal time (UTC)

                Console.WriteLine(d);
                
            }
            catch (IOException ioex)
            {
                Console.WriteLine(ioex.Message);
            }
        }
    }
}

/*
run:
   
3/12/2015 8:53:04 AM

*/


answered Mar 17, 2015 by avibootz

Related questions

1 answer 175 views
1 answer 133 views
1 answer 138 views
1 answer 174 views
2 answers 203 views
203 views asked Mar 24, 2021 by avibootz
...