Q:

C# program to set new file creation time

0

Given a file, and we have to define (set) a new file creation time using C# program.

File.SetCreationTime()

This is a method of "File" class, which is used to define a new file creation time.

Syntax:

void SetCreationTime(path, DateTime);

Parameter(s):

  1. path - Filename with its location.
  2. DateTime - Here we need to pass object of date time class..

Object of DateTime contains following information:

  1. Month
  2. Date
  3. Year
  4. Hour
  5. Minutes
  6. Seconds
  7. AM and PM
  8.  

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program

using System;
using System.IO;

namespace ConsoleApplication1
{
	class Program
	{
		static void Main()
		{
			DateTime D1 =  File.GetCreationTime("XYZ.TXT");
			Console.WriteLine("Old File Creation Time : "+D1.ToString());

			DateTime D2 = new DateTime(2017, 12, 25, 19, 45, 10);

			File.SetCreationTime("XYZ.TXT", D2);

			DateTime D3 = File.GetCreationTime("XYZ.TXT");
			Console.WriteLine("New File Creation Time : " + D3.ToString());
		}
	}
}

Output

Old File Creation Time : 10/27/2017 10:45:10 AM
New File Creation Time : 12/25/2017 7:45:10 PM

Note: In above program, we need to remember, when we use "File" class, System.IO namespace must be included in the program.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# file handling (File class) solved programs/examples

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to copy content of one file to another ... >>
<< C# program to get attributes of a specified file...