Free Support Forum - aspose.com

API to add custom property

Hello Aspose Support,

I intended to use custom properties in presentation document. At first I was expecting something similar to "Aspose.Words.Properties.CustomDocumentProperties". However it seems that the document property contains only a handful pre-defined properties, there is no way to add in any new property. While searched in this forum, it seemes customizing presentation properties is possible for Java. Did I miss anything or there could be a workaround somehow?!

Thanks for your help!

FYI, my snippet is as follows.

using (MemoryStream ms = new MemoryStream(contents))
{
Aspose.Slides.Presentation presentation = new Aspose.Slides.Presentation(ms);
Aspose.Slides.DocumentProperties props = presentation.DocumentProperties;

props.Add(propName, propValue); //Not available?

...
}

Hi Yiding,

I have observed that the requested feature for setting the custom document property in Aspose.Slides for .NET is unavailable. An issue with ID 26968 has been created in our issue tracking system as a new feature request to further investigate and resolve the issue specified. This thread has also been linked with the issue so that you may be automatically notified, once the feature is available.

Thanks and Regards,

Hi Yiding,

The support for adding custom document properties has been added in Aspose.Slides for .NE 5.4.0 and onward versions. Please use the following code snippets for your kind reference.

public static void AddPPTDocumentProperties()

{

String path = @"K:\";

Presentation presPPT= new Presentation();

//Getting Document Properties

DocumentProperties dProps = presPPT.DocumentProperties;

//Adding Custom properties

dProps["New Custom"] = 12;

dProps["My Name"] = "Mudassir";

dProps["Custom"] = 124;

//Finding some text in property

bool isPropertyPresent= dProps.Contains("Mudassir");

//Getting property name at particular index

String getPropertyName = dProps.GetPropertyName(2);

//Removing selected property

dProps.Remove(getPropertyName);

presPPT.Write(path + "temp.ppt");

}

public static void AddPPTXDocumentProperties()

{

String path = @"K:\";

PresentationEx presPPTX = new PresentationEx();

//Getting Document Properties

DocumentPropertiesEx dProps = presPPTX.DocumentProperties;

//Adding Custom properties

dProps["New Custom"] = 12;

dProps["My Name"] = "Mudassir";

dProps["Custom"] = 124;

//Finding some text in property

bool isPropertyPresent = dProps.Contains("Mudassir");

//Getting property name at particular index

String getPropertyName = dProps.GetPropertyName(2);

//Removing selected property

dProps.Remove(getPropertyName);

presPPTX.Write(path + "temp.pptx");

}

Thanks and Regards,

I tried to follow your instruction, but new customer properties are not added to the document.

Your instruction seems work only for existing properties. I want to dynamic generate custom properties without defining them in document.

Could you let me know how to make it work?

Thanks,

Hi Giang,


I have used the code snippet shared above using Aspose.Slides for .NET 6.8.0 and have observed no issue in it. In above code I have not used existing properties but added new ones instead. If you want to add the custom properties the following code from above code sample is responsible for that.

//Adding Custom properties

dProps[“New Custom”] = 12;

dProps[“My Name”] = “Mudassir”;

dProps[“Custom”] = 124;

For your kind reference, I have also attached the generated presentations. I have also attached the sample image depicting the added properties. Please share, if I may help you further in this regard.

Many Thanks,

Thanks for your instruction. It works for me.

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan