I'm looking to serialise individual PowerPoint slides and persist them on disk. The goal is to access the slide data later on and add them to other presentations. For our add-in, the number of slides to be persisted could grow fast and we'd rather not store them in PowerPoint files for performance reasons.
I've tried to persist the data in the clipboard for office 2010-2016 by getting the data format "PowerPoint 14.0 Slides Package" from the clipboard after copying a slide. I then read the files, set them back to the clipboard and paste them in the Slides collection of the target presentation.
But I'm not able to make this work for Office 2007 - there's no "slides package" format in the memory. The only clipboard clip that looks like it could store the slide data is "Embedded Object" but that doesn't seem to work as I'm not able to paste the slide again.
Is there a way to solve this? And am I missing a more elegant solution to the problem?
Here is my current code in C#:
public static string PptSlideClipFormat = "PowerPoint 14.0 Slides Package";
public static void serializeSlide(PowerPoint.Slide slide, string filePath)
{
slide.Copy();
var dataObject = Clipboard.GetDataObject();
MemoryStream myStream = (MemoryStream)Clipboard.GetData(PptSlideClipFormat);
IsolatedStorageFileStream fs = new IsolatedStorageFileStream(filePath, FileMode.Create, Utils.Common.isoStore);
try
{
myStream.WriteTo(fs);
}
catch
{
throw new Exception("Failed to serialize slide clipboard data");
}
finally
{
fs.Close();
}
Utils.Common.clearClipboard();
}
[…]
public static void deserializeSlide(string filePath)
{
IsolatedStorageFileStream fs = new IsolatedStorageFileStream(filePath, FileMode.OpenOrCreate, Utils.Common.isoStore);
try
{
Clipboard.SetData(PptSlideClipFormat, fs);
}
catch
{
throw new Exception("Failed to serialize slide clipboard data");
}
finally
{
fs.Close();
}
}