I want to set properties on files in .NET code. I have tried with DSOFile (v2.1) like this:
var properties = new OleDocumentProperties();
try
{
properties.Open(filePath);
properties.SummaryProperties.Title = "foo";
properties.Save();
}
finally
{
properties.Close();
}
It works fine with Office documents. (I've tested with Word and Excel.) However, I want to do it with other kinds of documents too. When I try with PDF or TXT files I get the following exception:
System.Runtime.InteropServices.COMException (0x800300FC): The name is not valid. (Exception from HRESULT: 0x800300FC (STG_E_INVALIDNAME)) at DSOFile._OleDocumentProperties.Save()
In addition to setting SummaryProperties, I'm also setting CustomProperties. This also works fine with Office files but not others. My file system is NTFS.
How can I set properties (standard and custom) this with DSOFile or with any other technique?
dsofile.dll
can be used edit Office document properties when you do not have Office installed (see Q224351. It can be used to modify COM Structured Storage persistent as a file. One can use StgCreateStorageEx with IID_IStorage
or IID_IPropertySetStorage
as a parameter to open the COM Structured Storage file and then use returned interface handler IStorage or IPropertySetStorage.
Old format of Microsoft Office documents (like .doc or .xls) are COM Structured Storage file. Later versions of the Microsoft Office documents has another XML based format. To be exactly all new Microsoft Office documents (like .docx or .xlsx) can be renamed in .zip and extracted to some XML files. Windows Installer still use COM Structured Storage file to represent the main .msi files and the transform files (.mst). One more example of COM Structured Storage file are .lnk files used for the Shortcuts. Structured Storage file can be useful in case if one tried to hold and modify many parts of different information in one file without risk to have corrupted files.
The binary format of Structured Storage files are described here.
NTFS has some support of IPropertyStorage and IPropertySetStorage interface for NTFS files when the files themselves are not compound files (see here and here), but I don't think that you will be able to save in the way any helpful information about PDF or TXT files.
User contributions licensed under CC BY-SA 3.0