We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Create, read and edit PowerPoint slides in C#

Platform: WinForms |
Control: Presentation |
Published Date: January 30, 2020 |
Last Revised Date: January 31, 2020

The following steps demonstrates how to create, read, and edit PowerPoint slides in a Windows forms application using the Presentation library.

 

Steps to create, read and edit PowerPoint slides Programmatically:

 

Step 1: Create a new Windows Forms application. Name it as GettingStarted.

Step 2: Install Presentation assemblies with NuGet

In Visual Studio, select Tools > NuGet Package Manager > Package Manager Console and execute the following command for the project.

install-package Syncfusion.Presentation.WinForms

Step 3: Add a new button to the form editor.


Step 4: Include the following code example in the click event of the button in Form.cs, to create a PowerPoint presentation and save it as a file.

//Creates PowerPoint Presentation
IPresentation pptxDoc = Presentation.Create();
//Adds slide to the PowerPoint
ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank);
//Adds textbox to the slide
IShape textboxShape = slide.AddTextBox(0, 0, 500, 500);
//Adds paragraph to the textbody of text box
IParagraph paragraph = textboxShape.TextBody.AddParagraph();
//Adds a TextPart to the paragraph
ITextPart textPart = paragraph.AddTextPart();
//Adds text to the TextPart
textPart.Text = "AdventureWorks Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Washington with 290 employees, several regional sales teams are located throughout their market base.";
//Saves the Presentation
pptxDoc.Save("Output.pptx");
//Closes the Presentation
pptxDoc.Close();

 

Step 5: Include the following code example in the click event of the button in Form.cs, to read and edit a PowerPoint presentation and save it as a file.

//Loads the PowerPoint Presentation
IPresentation pptxDoc = Presentation.Open("Sample.pptx");
//Gets the slide from Presentation
ISlide slide = pptxDoc.Slides[0];
//Gets the shape in slide
IShape textboxShape = slide.Shapes[0] as IShape;  
//Gets instance of a paragraph in a text box
IParagraph paragraph = textboxShape.TextBody.Paragraphs[0];
//Read the text in the paragraph
string text = paragraph.Text;
//Applies the first line indent of the paragraph
paragraph.FirstLineIndent = 10;
//Applies the horizontal alignment of the paragraph to center
paragraph.HorizontalAlignment = HorizontalAlignmentType.Left;
//Applies the left indent of the paragraph
paragraph.LeftIndent = 8;
//Saves the Presentation
pptxDoc.Save("Output.pptx");
//Closes the Presentation
pptxDoc.Close();

 

See Also:

Create a PowerPoint file in ASP.NET MVC

Create a PowerPoint file in ASP.NET

Create a PowerPoint file in Xamarin

Create a PowerPoint file in WPF

Create a PowerPoint file in UWP

Create a PowerPoint file in ASP.NET Core

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile