为什么自定义文件属性,使用DSOFile库设置,不节能之后持续? [英] Why do custom file properties, set using the DSOFile library, not persist after saving?

查看:324
本文介绍了为什么自定义文件属性,使用DSOFile库设置,不节能之后持续?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在为AutoCAD的一个插件,它允许用户使用文档版本控制应用程序进行交互,并以同步远程仓库和本地计算机之间的文件,我曾计划使用自定义文件属性。这些属性将被设置在第一次下载文件时,再坚持了,只要将文件保留在用户的本地驱动器上。我不是在AutoCAD的具体解决方案很感兴趣,因为我的插件会处理其他的文件比AutoCAD图形(文本文件,图像文件,等等)。因此,我希望有一个库,可以处理尽可能多的潜在的文件类型成为可能。

在寻找如何实现这种在C#中的事情,我几乎立即在整个DSOFile图书馆来了。一切我读到说,这是专为微软Office,但它应该与任何文件工作,只要文件系统是NTFS(至少这是我的理解)。我没有问题的文件,如纯文本文件(.txt)中,AutoCAD绘图(.DWG)和图像(.JPG,.TIF等)设置自定义属性。不过,我注意到,一旦这些文件被保存,自定义属性被消灭。在我所看见的自定义属性的唯一情况是持续保存后,分别在MS Office文档。我想这个问题涉及到,我是用来保存文件的应用软件(AutoCAD,MS画图,记事本等),但我不能100%肯定这一点。在我决定去与比使用DSOFile其他的解决方案,我想看看是否有人就因此不得不在这个问题的一些见解。

我测试用自己的code和使用随DSOFile演示,并看到了同样的结果两次。自定义属性被保存任何类型的文件比微软Office(Word和Excel)文件。

等后全军覆没

下面是类似code我会用添加一个新的自定义属性的示例...

  VAR docProperties =新OleDocumentProperties();
docProperties.Open(myfile.txt的假,dsoFileOpenOptions.dsoOptionDefault);

尝试
{
  对象值=一些价值;
  docProperties.CustomProperties.Add(MyCustomProp,参考值);
}

最后
{
  docProperties.Close(真正的); //保存并关闭
}
 

解决方案

这可能为时已晚,但我用这个有点或Autodesk Revit中RFA文件以及PDF格式文件,并能正常工作。您无法对其进行编辑,而RFA是开放的,但。

你叫docProperties.Save()呢?

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
}

解决方案

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?

这篇关于为什么自定义文件属性,使用DSOFile库设置,不节能之后持续?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆