We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Embedded Data Has Not Changed after Removing It and Saving File

Hi Aspose team,
I using Apsose slides version 22.4. And I want to remove ole object in ppt file.
Here is my current code:

        using(var inputStream = new FileStream(@"D:\sample.ppt", FileMode.Open,
                                               FileAccess.Read, FileShare.ReadWrite))
        {
            Presentation  presentation = new Presentation(inputStream);
            var slides = new List<IBaseSlide>(presentation.Slides);
            foreach(var slide in slides)
            {
                foreach(var shape in slide.Shapes)
                {
                    if(shape is OleObjectFrame ole)
                        if(ole.EmbeddedData.EmbeddedFileData != null && ole.EmbeddedData.EmbeddedFileData.Length > 0)
                        {
                            ole.ObjectProgId = "";
                            ole.SetEmbeddedData(new OleEmbeddedDataInfo(Array.Empty<byte>(), "data"));
                        }
                }
            }
            SaveFormat format = SaveFormat.Ppt;
            presentation.Save(@"D:\output.ppt", format);
        }

I tried to remove embedded data in ole object by using SetEmbeddedData(), I set it to empty array. When I debug, I see data in EmbeddedFileData removed. But after saving to output file, I use the output for this process at second time, the embedded data is back.
Is this a bug ? Can you give me some advice to remove it ?
Please help me investigate this issue.
sample.zip (329.7 KB)

@dunghnguyen,
Thank you for contacting support.

To remove an OLE object from a presentation, you should remove the OleObjectFrame object from the slide containing it. The following code example shows you how to remove all OLE objects from the presentation:

using (var presentation = new Presentation("sample.ppt"))
{
    foreach (var slide in presentation.Slides)
    {
        // Copy the shape collection from the current slide.
        var shapes = new List<IShape>(slide.Shapes);

        foreach (var shape in shapes)
        {
            if (shape is OleObjectFrame)
            {
                // Remove the OLE object frame from the slide.
                slide.Shapes.Remove(shape);
            }
        }
    }

    presentation.Save("sample_out.ppt", SaveFormat.Ppt);
}

More exampes: Manage OLE
API Reference: IShapeCollection.Remove Method

@Andrey_Potapov
When I debug with SetEmbeddedData function, embedde data has been removed and that’s the result I expected. I don’t want to remove all parts of ole, just remove embedded data in ole object.
Is there any other way to do it ?

@dunghnguyen,
It looks like OLE objects cannot exist without data. Could you please describe a case where this makes sense? What end goal do you want to achieve?