Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I extract the date from the "Media Created" column of a video file?

I need to extract the date from the "Media Created" column (highlighted in green in my the example photo below) using C#.

In my example, the "Media Created" and "Date" columns are the exact same. However, there are several instances where they are not. The "Media Created" column contains the correct date for when the video was actually recorded.

See this column?

Here is the function I used to get it. Thanks to Aziz for pointing me in the right direction:

Shell shell = new ShellClass();
Folder folder = shell.NameSpace(_File.DirectoryName);
FolderItem file = folder.ParseName(_File.Name);

// These are the characters that are not allowing me to parse into a DateTime
char[] charactersToRemove = new char[] {
    (char)8206,
    (char)8207
};

// Getting the "Media Created" label (don't really need this, but what the heck)
string name = folder.GetDetailsOf(null, 191);

// Getting the "Media Created" value as a string
string value = folder.GetDetailsOf(file, 191).Trim();

// Removing the suspect characters
foreach (char c in charactersToRemove)
    value = value.Replace((c).ToString(), "").Trim();

// If the value string is empty, return DateTime.MinValue, otherwise return the "Media Created" date
return value == string.Empty ? DateTime.MinValue : DateTime.Parse(value);
like image 594
Jason Thuli Avatar asked Dec 02 '11 04:12

Jason Thuli


2 Answers

The extended file properties can be obtained by using Folder.GetDetailsOf() method. As per this thread, the Media Created Date can be retrieved using a property id of 177.

like image 172
Aziz Avatar answered Sep 20 '22 14:09

Aziz


There are another way to retrieve data, using the Microsoft.WindowsAPICodePack.Shell namespace.

ShellObject shell = ShellObject.FromParsingName(path);

var data = shell.Properties.System.Media.DateEncoded;
like image 39
Rafael Cronemberger Avatar answered Sep 18 '22 14:09

Rafael Cronemberger