如何使用IpropertyStorage读取文件的属性?

如何使用iPropertyStorage读取文件的属性(如标题,作者,页数等)? 任何人都知道c#中的代码请发布

其实,

我正在尝试以编程方式(使用c#)读取文件属性(标题,摘要,作者,注释等……当您看到文件的属性时显示在摘要选项卡上的内容)。

FileInfo和FileSystemInfo类只公开标准属性(创建时间,模式时间等)。所以我正在尝试使用ipropertyStorage。 任何人都知道解决方案后它会有所帮助。

像这样的Shell编程总是很难做到。 虽然shell32.dll有一个可以从COM客户端调用的自动化接口,但你在这个上有一个战斗机会。 ShellFolderItem :: ExtendedProperty属性使它们可用。 您需要一个WPF或Windows窗体项目,以便正确初始化COM。 使用Project + Add Reference,Browse选项卡,选择c:\ windows \ system32 \ shell32.dll。 此示例代码读取c:\ temp \ test.txt文件的Author属性:

Shell32.Shell shl = new Shell32.ShellClass(); Shell32.Folder dir = shl.NameSpace(@"c:\temp"); Shell32.FolderItem itm = dir.Items().Item("test.txt"); Shell32.ShellFolderItem itm2 = (Shell32.ShellFolderItem)itm; string prop = (string)itm2.ExtendedProperty("{F29F85E0-4FF9-1068-AB91-08002B27B3D9} 4"); Console.WriteLine(prop); 

您可以使用的属性ID(PID)值记录在此SDK文章中 。