How to modify a file date and time in C#

2 Answers

0 votes
using System;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine(File.GetLastWriteTime("d:\\data.txt"));
                File.SetLastWriteTime("d:\\data.txt", DateTime.Now);
                Console.WriteLine(File.GetLastWriteTime("d:\\data.txt"));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

/*
run:

2/18/2014 3:40:05 AM
6/15/2015 9:35:11 PM
 
*/

 



answered Jun 15, 2015 by avibootz
0 votes
using System;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine(File.GetLastWriteTime("d:\\data.txt"));

                // The first file that found in antarctica...
                File.SetLastWriteTime("d:\\data.txt", new DateTime(1610, 2, 18, 3, 40, 5));

                Console.WriteLine(File.GetLastWriteTime("d:\\data.txt"));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

/*
run:

6/15/2015 9:35:11 PM
2/18/1610 3:40:05 AM
 
*/

 



answered Jun 15, 2015 by avibootz

Related questions

1 answer 214 views
1 answer 1,188 views
1,188 views asked Jun 19, 2015 by avibootz
1 answer 236 views
236 views asked Jun 18, 2015 by avibootz
1 answer 298 views
1 answer 281 views
2 answers 257 views
...