Aspose.Slides for .NET How to add new Custom property to DocumentPropeties

Hello,

I have a need to add a Custom Property to a presentation. I saw your post Presentation Properties - Access or Modify PowerPoint Presentation Properties in C#|Aspose.Slides Documentation on how to change value to existing property. I need to add a custom property ‘_MarkAsFinal’ and set it to ‘True’. Could you please explain me how to do that?

This code from your example would not work if property does not exist. IDocumentProperties has Remove() method but does not have Add(). How to add a new custom property?

IDocumentProperties dp = pres.DocumentProperties;

//Access and modify custom properties
for (int i = 0; i < dp.Count; i++)
{
    //Display names and values of custom properties
    System.Console.WriteLine("Custom Property Name: " + dp.GetPropertyName(i));
    System.Console.WriteLine("Custom Property Value: " + dp[dp.GetPropertyName(i)]);

    //Modify values of custom properties
    dp[dp.GetPropertyName(i)] = "New Value " + (i + 1);
}

Thank you,
Natasha Turchak

Hi Natasha Turchak,

I have observed the requirements shared by you and suggest by you and suggest you to please look for heading, “Adding Custom Document Properties ” in this documentation link to add custom property. Please shape, if i may help you further in this regard.

Many Thanks,

Thank you for your reply however it is not very helpful.

In my case IDocumentProperties dp = presentation.DocumentProperties;
dp has no custom properties, Count =0.
You cannot modify something that does not exist as suggested in your referenced documentation code snippet:
 dp[dp.GetPropertyName(i)] = "New Value " + (i + 1);

dp.GetPropertyName(0) throws error.
My question is how to add a new custom property to IDocumentProperties object
 if it has none?

Thank you,

Natasha

Hi Natasha,

I have worked over the requirements shared by you and have created the sample code that will serve the purpose for you.

public static void AddCustom()
{
//Instantiate the Presentation class
Presentation presPPTX = new Presentation();

//Getting Document Properties
IDocumentProperties dProps = presPPTX.DocumentProperties;
int count1 = dProps.Count;
//Adding Custom properties
dProps[“New Custom”] = 12;
dProps[“My Name”] = “Mudassir”;
dProps[“Custom”] = 124;

//Getting property count
int count = dProps.Count;

//Saving presentation
presPPTX.Save(“D:\Aspose Data\CustomDemo.pptx”, Aspose.Slides.Export.SaveFormat.Pptx);
}

Please share, if I may help you further in this regard.

Many Thanks,