tags:

views:

141

answers:

1

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
}
A: 

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?

RodH257
@RodH257: As far as I can tell, it seems to be dependent on the application that is saving the file. As previously mentioned, I had no issues setting the properties for any file. The only time I had any problems is when I saved a file using AutoCAD (more specifically, the 2010 version). Whatever AutoCAD is doing when it saves a drawing, it's wiping out those property values. It may very well work with Revit, Acrobat, or any other number of apps.
Justin Holzer
ah I see, in my case I'm hooking into the document closed event in Revit and re-rewriting the properties I desire each time, so even if Revit does wipe the properties like AutoCAD did for you, it will re-add them. I don't think I've had an instance of me using DSOFile where that has been the case, so I haven't run into your problem! When I get the chance I might see if Revit does it, just out of interest.
RodH257