Home » .Net » C# file handling programs

C# program to set new file creation time

In this C# program, we are going to learn how to set (define) a new file creation time? Here, method File.SetCreationTime() is using to define a new time of file creation.
Submitted by IncludeHelp, on October 29, 2017

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

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.





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.