简体   繁体   English

如何在c#中读取自定义文件属性

[英]How to read custom file properties in c#

I'm looking for a way to read document properties in C#. 我正在寻找一种在C#中读取文档属性的方法。 I've heard about dsofile.dll, but it seems like an old COM wrapper, and was wondering if there is something more modern for the .NET framework/C#. 我听说过dsofile.dll,但它似乎是一个旧的COM包装器,并且想知道.NET框架/ C#是否有更现代的东西。 What I'm actually reading is not an office document file, but a Solidworks .SLDDRW file, that has Custom properties. 我实际阅读的不是Office文档文件,而是具有自定义属性的Solidworks .SLDDRW文件。 You can view and change these in Windows Explorer by right-clicking on the file, and going to the Properties window, Custom tab. 您可以在Windows资源管理器中通过右键单击该文件来查看和更改这些内容,然后转到“属性”窗口的“自定义”选项卡。

Anyone know how to read these custom properties in C# / .NET 3.5? 任何人都知道如何在C#/ .NET 3.5中阅读这些自定义属性?

Thanks! 谢谢!

The SolidWorks system uses the OLE Document Properties API. SolidWorks系统使用OLE文档属性API。 As you've pointed out, Microsoft offers a sample, DSOFile.dll, that allows you to access these properties: 正如您所指出的,Microsoft提供了一个示例DSOFile.dll,允许您访问这些属性:

http://support.microsoft.com/kb/224351 http://support.microsoft.com/kb/224351

The SolidWorks API also has robust support for these properties, but you have to load Solidworks to use the API, so it's not always the ideal solution. SolidWorks API还对这些属性提供了强大的支持,但您必须加载Solidworks才能使用API​​,因此它并不总是理想的解决方案。 Note that if the file is already open in Solidworks, however, you won't be able to edit custom properties using DSOfile.dll. 请注意,如果文件已在Solidworks中打开,则无法使用DSOfile.dll编辑自定义属性。

The simple answer to your question is that there isn't an updated API for these properties; 对您的问题的简单回答是,没有针对这些属性的更新API; much the same way many other legacy APIs (DDE, for example) continue to appear in production environments, DSOFile suits the need and honestly wouldn't be entirely appropriate for update due to its fairly low-level nature. 与许多其他传统API(例如DDE)继续出现在生产环境中的方式大致相同,DSOFile非常适合需要,并且由于其相当低级的特性,实际上并不完全适合更新。 DSOFile, however, is perfectly capable of handling your needs and it works quite cleanly with .NET. 然而,DSOFile完全能够满足您的需求,并且与.NET相当干净。 The source is available and can be compiled to 64 bit if that is an issue for your users; 源是可用的,如果这对您的用户来说是个问题,可以编译为64位; it does mean you need a separate 64 bit install, but that's a small price to pay (plus SolidWorks isn't exactly cross-bitness-friendly to begin with). 它确实意味着你需要一个单独的64位安装,但这是一个很小的代价(加上SolidWorks并不是开始时的交叉位数)。

If I understand you correctly, this thread has the answer for you: 如果我理解正确,这个帖子就有答案:

Read/Write 'Extended' file properties (C#) 读/写'扩展'文件属性(C#)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM