Load and Save the PowerPoint Presentation
3 Aug 20269 minutes to read
Prerequisites
Before you start, ensure the required Syncfusion assemblies or NuGet packages are installed. For more information, see Assemblies-Required and NuGet-Packages-Required.
Opening an existing presentation from the file system
You can open an existing PowerPoint presentation by using the file name and its physical path.
//Opens an existing PowerPoint presentation from the file system
IPresentation pptxDoc = Presentation.Open("Sample.pptx");//Opens an existing presentation from the file system
IPresentation pptxDoc = Presentation.Open("Sample.pptx");'Opens an existing presentation from the file system
Dim pptxDoc As IPresentation = Presentation.Open("Sample.pptx")You can download a complete working sample from GitHub.
Opening an existing presentation from a stream
You can open an existing PowerPoint presentation from a stream by using the overloads of the Open method. Always dispose the stream after opening to release the file handle.
FileStream inputStream = new FileStream(inputFileName, FileMode.Open)
//Opens an existing PowerPoint presentation from a stream
IPresentation pptxDoc = Presentation.Open(inputStream);FileStream inputStream = new FileStream(inputFileName, FileMode.Open)
//Opens an existing presentation from a stream
IPresentation pptxDoc = Presentation.Open(presentationStream);Dim inputStream As New FileStream(inputFileName, FileMode.Open)
'Opens an existing presentation from a stream
Dim pptxDoc As IPresentation = Presentation.Open(presentationStream)You can download a complete working sample from GitHub.
Opening an encrypted presentation
You can open an encrypted PowerPoint presentation from either a file path or a stream by using the following overloads of the Open method.
Opening from a stream
FileStream presentationStream = new FileStream(inputFileName, FileMode.Open)
//Opens an existing encrypted presentation from a stream
IPresentation pptxDoc = Presentation.Open(presentationStream, password);FileStream presentationStream = new FileStream(inputFileName, FileMode.Open)
//Opens an existing encrypted presentation from a stream
IPresentation pptxDoc = Presentation.Open(presentationStream, password);Dim inputStream As New FileStream(inputFileName, FileMode.Open)
'Opens an existing encrypted presentation from a stream
Dim pptxDoc As IPresentation = Presentation.Open(presentationStream, password)Opening from the file system
//Opens an existing encrypted presentation from the file system
IPresentation pptxDoc = Presentation.Open(fileName, password);//Opens an existing encrypted presentation from the file system
IPresentation pptxDoc = Presentation.Open(fileName, password);'Opens an existing encrypted presentation from the file system
Dim pptxDoc As IPresentation = Presentation.Open(fileName, password)You can download a complete working sample from GitHub.
Saving a PowerPoint presentation to the file system
You can save the created or manipulated PowerPoint presentation to the file system by using the Save() method of the IPresentation interface. The default format type is .pptx. To save in a different format, pass a FormatType value (for example, FormatType.Ppt or FormatType.Pdf).
//Opens an existing PowerPoint presentation
IPresentation pptxDoc = Presentation.Open(fileName);
//To-Do some manipulation
//Saves the presentation to the file system
pptxDoc.Save("Output.pptx");//Opens an existing PowerPoint presentation
IPresentation pptxDoc = Presentation.Open(fileName);
//To-Do some manipulation
//Saves the presentation to the file system
pptxDoc.Save("Output.pptx");'Opens an existing PowerPoint presentation
Dim pptxDoc As IPresentation = Presentation.Open(fileName)
'To-Do some manipulation
'Saves the presentation to the file system
pptxDoc.Save("Output.pptx")You can download a complete working sample from GitHub.
Saving a PowerPoint presentation to a stream
You can save the created or manipulated PowerPoint presentation to a stream by using the overloads of the Save method.
//Opens an existing PowerPoint presentation
IPresentation pptxDoc = Presentation.Open(inputFileName);
//To-Do some manipulation
MemoryStream stream = new MemoryStream();
pptxDoc.Save(stream);//Opens an existing PowerPoint presentation
IPresentation pptxDoc = Presentation.Open(fileName);
//To-Do some manipulation
//Creates an instance of memory stream
MemoryStream stream = new MemoryStream();
//Saves the presentation to a stream
pptxDoc.Save(stream);'Opens an existing PowerPoint presentation
Dim pptxDoc As IPresentation = Presentation.Open(fileName)
'To-Do some manipulation
'Creates an instance of memory stream
Dim stream As New MemoryStream()
'Saves the presentation to a stream
pptxDoc.Save(stream)You can download a complete working sample from GitHub.
Sending to a client browser
You can save and send the presentation to a client browser from a website or web application by invoking the overload of the Save method. This method explicitly makes use of an instance of HttpResponse as its parameter in order to stream the presentation to the client browser. So, this overload is suitable for a web application that references the System.Web assembly.
//Opens an existing PowerPoint presentation
IPresentation pptxDoc = Presentation.Open(inputFileName);
//To-Do some manipulation
//Saves the PowerPoint presentation to a memory stream
using (MemoryStream outputStream = new MemoryStream())
{
pptxDoc.Save(outputStream);
outputStream.Position = 0;
//Set the response content type and return the file
string contentType = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
return File(outputStream, contentType, outputFileName);
}//Opens an existing PowerPoint presentation
IPresentation pptxDoc = Presentation.Open(fileName);
//To-Do some manipulation
//Saves the presentation to the client browser
pptxDoc.Save("Output.pptx", FormatType.Pptx, Response);'Opens an existing PowerPoint presentation
Dim pptxDoc As IPresentation = Presentation.Open(fileName)
'To-Do some manipulation
'Saves the presentation to the client browser
pptxDoc.Save("Output.pptx", FormatType.Pptx, Response)You can download a complete working sample from GitHub.
Closing a PowerPoint presentation
When you are done with the Presentation instance, you should close the instance of IPresentation in order to release the memory consumed by the Syncfusion PowerPoint library. The following code example illustrates how to close an IPresentation instance.
//Opens an existing PowerPoint presentation
IPresentation pptxDoc = Presentation.Open(inputFileName);
//To-Do some manipulation
//Saves the PowerPoint presentation to the file system
pptxDoc.Save(OutputFileName);
//Closes the instance of the PowerPoint presentation
pptxDoc.Close();//Opens an existing presentation from the file system
IPresentation pptxDoc = Presentation.Open(fileName);
//To-Do some manipulation
//Creates an instance of memory stream
MemoryStream stream = new MemoryStream();
//Saves the presentation to a stream
pptxDoc.Save(stream);
//Closes the presentation instance and frees the memory consumed
pptxDoc.Close();'Opens an existing presentation from the file system
Dim pptxDoc As IPresentation = Presentation.Open(fileName)
'To-Do some manipulation
'Creates an instance of memory stream
Dim stream As New MemoryStream()
'Saves the presentation to a stream
pptxDoc.Save(stream)
'Closes the presentation instance and frees the memory consumed
pptxDoc.Close()You can download a complete working sample from GitHub.