2011-12-02 49 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

我已将我的工作功能添加到我的问题的底部。 –