8
我需要使用C#從「媒體創建」列(在下面的示例照片中以綠色突出顯示)中提取日期。如何從視頻文件的「Media Created」列中提取日期?
在我的示例中,「Media Created」和「Date」列完全相同。但是,有幾種情況並非如此。 「媒體創建」列包含實際錄製視頻的正確日期。
這裏是我用來獲取它的功能。由於阿茲指着我在正確的方向:
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);
這工作完美,除了一些事情。 屬性ID是191.我猜它必須與操作系統(我在Windows 7 64位)。 也有在有一些奇怪的字符,不會解析成一個DateTime正確: (焦炭)8206 (焦炭)8207 但是,一旦他們被剝奪了它完美地工作! 非常感謝! –
我已將我的工作功能添加到我的問題的底部。 –