如何使用iPropertyStorage读取文件的属性(如标题、作者、页数等)?任何知道c#代码的人请把它张贴出来
实际上,
我正在尝试以编程方式(使用c#)读取文件属性(标题、摘要、作者、注释等)。当您看到文件的属性时,在Summary选项卡上显示的内容)。
FileInfo和FileSystemInfo类仅公开标准属性(创建时间、修改时间等)。所以我尝试使用ipropertyStorage。任何知道它的解决方案的人都会很有帮助。
发布于 2010-02-15 21:50:05
像这样的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 article中。
https://stackoverflow.com/questions/2265759
复制相似问题