4

I need to add custom file properties (see here) to thousands of files programmatically.
The WindowsAPICodePack can get/set existing file properties, but it seems it can not add custom properties?!?


Here the code that works based on Add new metadata properties to a file:

You must reference the DSOFile.dll which can be downloaded from Microsoft here:
Microsoft Developer Support OLE File Property Reader 2.1 Sample

using DSOFile;

OleDocumentProperties myFile = new DSOFile.OleDocumentProperties();
myFile.Open(@"c:\temp\B30700.asm", false, DSOFile.dsoFileOpenOptions.dsoOptionDefault);

bool property_exists;
object prop_value;

prop_value = "999";

//Then check if there's already a property like the one you want to create
property_exists = false;

foreach (DSOFile.CustomProperty property in myFile.CustomProperties)
{
    if (property.Name == "Your Property Name")
    {
        //Property exists
        //End the task here (return;) oder edit the property
        property_exists = true;
        property.set_Value(prop_value);
    }
}

if (!property_exists)
    myFile.CustomProperties.Add("Your Property Name", ref prop_value);

myFile.Save();
myFile.Close(true);
Jimi
  • 29,621
  • 8
  • 43
  • 61
Ezra
  • 161
  • 1
  • 11
  • @Jimi yes [Add new metadata properties to a file](https://stackoverflow.com/questions/19947887/add-new-metadata-properties-to-a-file) solved my problem, thank you very much – Ezra Jan 16 '19 at 07:45
  • You're welcome :) Btw, your question will be closed as a duplicate. Don't worry about this, it's the *normal procedure*. But, if you want, you can answer your own question, posting the code you have (not a copy&paste of the duplicate) as the answer. Before the question is closed, that is. – Jimi Jan 16 '19 at 07:52
  • @Jimi I already marked the question as duplicate, so I can't answer anymore. I edited my original question with the code. – Ezra Jan 16 '19 at 07:59
  • Allright then, this will keep your question alive. – Jimi Jan 16 '19 at 08:01

0 Answers0