为什么使用 DSOFile 库设置的自定义文件属性在保存后不保留?

发布于 2024-09-02 04:51:43 字数 1032 浏览 1 评论 0原文

我目前正在开发一个 AutoCAD 插件,该插件允许用户与文档版本控制应用程序进行交互,并且为了在远程存储库和本地计算机之间同步文件,我计划使用自定义文件属性。这些属性将在最初下载文件时设置,然后只要文件保留在用户的本地驱动器上,就会一直保留。我对 AutoCAD 特定的解决方案并不真正感兴趣,因为我的插件将处理 AutoCAD 图形以外的文件(文本文件、图像文件等)。因此,我想要一个可以处理尽可能多的潜在文件类型的库。

当寻找如何在 C# 中实现这种事情时,我几乎立即遇到了 DSOFile 库。我读到的所有内容都说它是为 MS Office 设计的,但它应该适用于任何文件,只要文件系统是 NTFS(至少这是我的理解)。我在纯文本文档 (.txt)、AutoCAD 绘图 (.dwg) 和图像(.jpg、.tif 等)等文件上设置自定义属性没有问题。但是,我注意到一旦保存任何这些文件,自定义属性就会被清除。我看到自定义属性在保存后仍然保留的唯一情况是在 MS Office 文档上。我认为这个问题与我用来保存文件的应用程序(AutoCAD、MS Paint、记事本等)有关,但我不能 100% 确定这一点。在我决定使用 DSOFile 之外的解决方案之前,我想看看 SO 上是否有人对这个问题有一些见解。

我使用自己的代码和 DSOFile 附带的演示进行了测试,两次都看到了相同的结果。保存除 MS Office(Word 和 Excel)文档之外的任何类型的文件后,自定义属性都会被清除。

这是一个类似于我用来添加新的自定义属性的代码的示例......

var docProperties = new OleDocumentProperties();
docProperties.Open("myfile.txt", false, dsoFileOpenOptions.dsoOptionDefault);

try
{
  object value = "some value";
  docProperties.CustomProperties.Add("MyCustomProp", ref value);
}

finally
{
  docProperties.Close(true); // save and close
}

I am currently working on a plugin for AutoCAD that allows users to interact with a document versioning application, and in order to sync files between the remote repository and local machine, I had planned on using custom file properties. The properties would be set when a file is initially downloaded, and then persisted for as long as the file remains on the user's local drive. I am not really interested in an AutoCAD-specific solution, because my plugin will deal with files other than AutoCAD drawings (text files, image files, among others). Therefore, I want a library that can handle as many potential file types as possible.

When searching for how to implement this kind of thing in C#, I almost immediately came across the DSOFile library. Everything I read said it was designed for MS Office, but that it should work with any file, as long as the file system is NTFS (at least that's my understanding). I had no problem setting custom properties on files such as plain-text documents (.txt), AutoCAD drawings (.dwg), and images (.jpg, .tif, etc). However, I noticed that once any of these files were saved, the custom properties were wiped out. The only case in which I saw custom properties were persisted after saving, were on MS Office documents. I figured this issue was related to the application that I was using to save the files (AutoCAD, MS Paint, notepad, etc), but I can't be 100% sure of that. Before I decide to go with a solution other than using DSOFile, I wanted to see if anyone on SO had some insight in to this issue.

I tested using my own code and using the demo that comes with DSOFile, and saw the same result both times. Custom properties were wiped out after saving any type of file other than an MS Office (Word and Excel) document.

Here is an example similar to the code I would use to add a new custom property...

var docProperties = new OleDocumentProperties();
docProperties.Open("myfile.txt", false, dsoFileOpenOptions.dsoOptionDefault);

try
{
  object value = "some value";
  docProperties.CustomProperties.Add("MyCustomProp", ref value);
}

finally
{
  docProperties.Close(true); // save and close
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往事风中埋 2024-09-09 04:51:43

这可能为时已晚,但我已经使用过一点或 Autodesk Revit RFA 文件以及 PDF 文件,并且工作正常。不过,当 RFA 打开时您无法编辑它们。

您是否调用了 docProperties.Save() ?

This may be too late but I've used this a bit or Autodesk Revit RFA files as well as PDF files and it works fine. You can't edit them while the RFA is open though.

Did you call docProperties.Save() at all?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文