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
}