File.GetCreationTime() Method in C# with Examples
File.GetCreationTime(String) is an inbuilt File class method which is used to return the creation date and time of the specified file or directory.
public static DateTime GetCreationTime (string path);
Parameter: This function accepts a parameter which is illustrated below:
- path: This is the specified file path whose creation date and time is going to be returned.
- UnauthorizedAccessException: The caller does not have the required permission.
- ArgumentException: The path is a zero-length string, contains only white space, or one or more invalid characters as defined by InvalidPathChars.
- ArgumentNullException: The path is null.
- PathTooLongException: The given path, file name, or both exceed the system-defined maximum length.
- NotSupportedException: The path is in an invalid format.
Return Value: Returns the creation date and time of the specified file or directory.
Below are the programs to illustrate the File.GetCreationTime(String) method.
Program 1: Before running the below code, a file file.txt is created with some contents shown below:
File created on: 4/19/2020 4:02:54 AM
Program 2: Before running the below code, two files were created shown below:
File created on: 4/19/2020 4:02:54 AM File created on: 4/19/2020 4:07:02 AM