Lynx
Lynx

Reputation: 257

Read video information(date created)?

In window, i can get the date created of the video from properties(right click).
I have a few idea on this but i dont know how to do it.
1. Get the video information directly from video(like in windows),
2. By extracting the video name to get the date created(The video's name is in date format, which is the time it created).
And i also using taglib-sharp to get the video duration and resolution, but i cant find any sample code on how to get the video creation date.

Note: video name in date format - example, 20121119_125550.avi

Edit
Found this code and so far its working

string fileName = Server.MapPath("//video//20121119_125550.avi");
FileInfo fileInfo = new FileInfo(fileName);
DateTime creationTime = fileInfo.CreationTime;

Output: 2012/11/19 12:55:50

For the file's name, i will add another string in name. For example User1-20121119_125550.avi.avi, so it will get complicated after that.

Upvotes: 0

Views: 2257

Answers (1)

JoshVarty
JoshVarty

Reputation: 9426

If you can safely trust your filenames, you may be content with the following:

string file_name = "20121119_125550.avi";
string raw_date = file_name.Split('.')[0];
CultureInfo provider = CultureInfo.InvariantCulture;


string format = "yyyyMMdd_hhmmss";
DateTime result = DateTime.ParseExact(raw_date, format, provider);

Note: You'll likely need to add using System.Globalization; to any file you wish to use this in.

If you just want the date the file was created (What you see in Windows Explorer) you can just use:

string file_path = @"C:\20121119_125550.avi"; //Add the correct path
DateTime result = File.GetCreationTime(file_path);

Upvotes: 1

Related Questions