2011-12-02 41 views
8

我需要使用C#從「媒體創建」列(在下面的示例照片中以綠色突出顯示)中提取日期。如何從視頻文件的「Media Created」列中提取日期?

在我的示例中,「Media Created」和「Date」列完全相同。但是,有幾種情況並非如此。 「媒體創建」列包含實際錄製視頻的正確日期。

See this column?

這裏是我用來獲取它的功能。由於阿茲指着我在正確的方向:

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); 

回答

3

擴展文件屬性可以通過使用Folder.GetDetailsOf()方法得到。 根據這thread媒體創建日期可以檢索使用屬性ID爲177.

+0

這工作完美,除了一些事情。 屬性ID是191.我猜它必須與操作系統(我在Windows 7 64位)。 也有在有一些奇怪的字符,不會解析成一個DateTime正確: (焦炭)8206 (焦炭)8207 但是,一旦他們被剝奪了它完美地工作! 非常感謝! –

+0

我已將我的工作功能添加到我的問題的底部。 –