OLE Object
This article demonstrates embedding a file as an OLE object and updating its data using Aspose.Slides for .NET.
Copy a C# block into Program.cs in a .NET project with Aspose.Slides.NET6.CrossPlatform installed. Each block is a complete program. Run one block at a time. The ZIP contains the IDE-ready project and its verification checks. The copied code runs in evaluation mode. For licensed output, apply your license before creating a presentation, as described in the licensing guide.
Download and run
Download the complete project, extract it, and open Example.sln or run:
dotnet restore Example.sln
dotnet run --project Example.csproj -- --mode evaluation
The download includes every case below, its fixture helpers and inputs. Program.cs runs all cases; use --action block-001 to run one independently. Outputs and an action report are written to the printed output directory. No previous example or working-directory setup is required. Evaluation adds a watermark and can truncate read-back text; the short fixtures still have explicit structural checks. For full text and no watermark, use --mode licensed --license PATH with your own valid license. See the setup guide for supported SDKs and native prerequisites.
Add an OLE Object
Generate a PDF payload in memory from the blank presentation, then embed it in an OLE frame. No PDF file is required.
using System.IO;
using Aspose.Slides.Export;
using Aspose.Slides;
using Aspose.Slides.DOM.Ole;
using var presentation = new Presentation();
var slide = presentation.Slides[0];
// Create the PDF payload in memory from the blank presentation.
using var pdfStream = new MemoryStream();
presentation.Save(pdfStream, SaveFormat.Pdf);
var pdfData = pdfStream.ToArray();
var dataInfo = new OleEmbeddedDataInfo(pdfData, "pdf");
slide.Shapes.AddOleObjectFrame(20, 20, 50, 50, dataInfo);
presentation.Save("ole-object-01.pptx", SaveFormat.Pptx);
Access an OLE Object
Generate a PDF payload in memory, embed it, then retrieve the first OLE frame and print its file extension. No input file is required.
using System;
using System.IO;
using Aspose.Slides.Export;
using System.Linq;
using Aspose.Slides;
using Aspose.Slides.DOM.Ole;
using var presentation = new Presentation();
var slide = presentation.Slides[0];
// Create the PDF payload in memory from the blank presentation.
using var pdfStream = new MemoryStream();
presentation.Save(pdfStream, SaveFormat.Pdf);
var pdfData = pdfStream.ToArray();
var dataInfo = new OleEmbeddedDataInfo(pdfData, "pdf");
slide.Shapes.AddOleObjectFrame(20, 20, 50, 50, dataInfo);
var firstOleFrame = slide.Shapes.OfType<IOleObjectFrame>().First();
Console.WriteLine(firstOleFrame.EmbeddedData.EmbeddedFileExtension);
presentation.Save("ole-object-02.pptx", SaveFormat.Pptx);
Remove an OLE Object
Generate and embed a PDF payload in memory, then remove its OLE frame. No input file is required.
using System.IO;
using Aspose.Slides.Export;
using Aspose.Slides;
using Aspose.Slides.DOM.Ole;
using var presentation = new Presentation();
var slide = presentation.Slides[0];
// Create the PDF payload in memory from the blank presentation.
using var pdfStream = new MemoryStream();
presentation.Save(pdfStream, SaveFormat.Pdf);
var pdfData = pdfStream.ToArray();
var dataInfo = new OleEmbeddedDataInfo(pdfData, "pdf");
var oleFrame = slide.Shapes.AddOleObjectFrame(20, 20, 50, 50, dataInfo);
slide.Shapes.Remove(oleFrame);
presentation.Save("ole-object-03.pptx", SaveFormat.Pptx);
Update OLE Object Data
Generate and embed a PDF payload in memory, then replace its data with the included small PNG. Both payloads are created by the program; no input files are required.
using System;
using System.IO;
using Aspose.Slides.Export;
using Aspose.Slides;
using Aspose.Slides.DOM.Ole;
using var presentation = new Presentation();
var slide = presentation.Slides[0];
// Create the PDF payload in memory from the blank presentation.
using var pdfStream = new MemoryStream();
presentation.Save(pdfStream, SaveFormat.Pdf);
var pdfData = pdfStream.ToArray();
var dataInfo = new OleEmbeddedDataInfo(pdfData, "pdf");
var oleFrame = slide.Shapes.AddOleObjectFrame(20, 20, 50, 50, dataInfo);
// Replace the PDF payload with a small PNG.
var pngData = Convert.FromBase64String(
"iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAIAAAADnC86AAAAMElEQVR4nO3NQQkAAAgEsItoJiOa" +
"yBKCn8H+S02/iFgsFovFYrFYLBaLxWKxWHxnAfyWQZeVYs/3AAAAAElFTkSuQmCC");
var newDataInfo = new OleEmbeddedDataInfo(pngData, "png");
oleFrame.SetEmbeddedData(newDataInfo);
presentation.Save("ole-object-04.pptx", SaveFormat.Pptx);