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); 
4
  • @Jimi yes Add new metadata properties to a file solved my problem, thank you very much Commented Jan 16, 2019 at 7: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. Commented Jan 16, 2019 at 7:52
  • @Jimi I already marked the question as duplicate, so I can't answer anymore. I edited my original question with the code. Commented Jan 16, 2019 at 7:59
  • Allright then, this will keep your question alive. Commented Jan 16, 2019 at 8:01

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.