Unable to cast object of type Aspose.Slides.Placeholder to Aspose.Slides.TextHolder

Hi there

I’m trying to retrieve the text from a textholder on a slide, but I get the error message above for certain
shapes. I’m using the code provided in the Aspose.Slides helpfile to do this -

Shape shp = sld.Shapes[shpIdx];

//Get the paragraphs from textholder or textframe

Paragraphs paras = null;

//Check if shape holds a textholder

if (shp.Placeholder != null && shp.IsTextHolder == true)

{

TextHolder thld = (TextHolder)shp.Placeholder;

paras = thld.Paragraphs;

}



but the issue occurs nonetheless. I was wondering what causes it and if there is a workaround?

Thanks

Eric

Hello Eric,

That is possible that text can be stored directly in a shape’s TextFrame even for Placeholder. In this case you don’t need to cast Placeholder. Try something like this:

if (shp.TextFrame != null)
{
paras = shp.TextFrame.Paragraphs;
}
else if (shp.Placeholder != null && shp.IsTextHolder == true)
{
TextHolder thld = shp.Placeholder as TextHolder;
if (thld != null)
paras = thld.Paragraphs;
}