PPT/PPTX files are most widely used in business and educational organizations. These files are used to deliver various types of presentations. Moreover, you can insert rich media items and set eye-catching layouts to make your presentation even more attractive and readable. However, manipulating a huge number of PPT files manually takes an immense amount of time. Therefore, we’ll use this C# PowerPoint library to compare two PowerPoint Files in C# programmatically.
We will cover the following points:
- C# PowerPoint library
- Compare two PowerPoint files in C#
- Retrieve PowerPoint Slide Properties Programmatically in C#
C# PowerPoint library
This library is lightweight and offers comprehensive documentation regarding installation. Therefore, you can either download this C# PowerPoint library or install it by running the following commands in the NuGet PM.
Install-Package Aspose.Slides.NET
Compare two PowerPoint files in C#
You can use this powerful library to process and manipulate your presentation slides programmatically in C#.
Please follow the steps and the code snippets mentioned here:
- Load the two PPTX files by creating an instance of the Presentation class.
- Access the Masters property that returns a list of all master slides that are defined in the presentation.
- Loop through all the slides of both PPTX files.
- Check if there is a match among the slides of both PPTX files by invoking the Equals method.
Copy & paste the following code into your main file to compare PowerPoint presentations in C#:
//how to compare two powerpoint presentations | |
// Load the first PPTX file by creating an instance of the Presentation class | |
using (Presentation presentation1 = new Presentation("sample.pptx")) | |
// Load the second PPTX file by creating another instance of the Presentation class | |
using (Presentation presentation2 = new Presentation("sample2.pptx")) | |
{ | |
// Access the Masters property that returns a list of all master slides that are defined in the presentation. | |
for (int i = 0; i < presentation1.Masters.Count; i++) | |
{ | |
// Loop through all the slides of both PPTX files | |
for (int j = 0; j < presentation2.Masters.Count; j++) | |
{ | |
// Check if there is a match among the slides of the both PPTX file by invoking the Equals method | |
if (presentation1.Masters[i].Equals(presentation2.Masters[j])) | |
Console.WriteLine(string.Format("SomePresentation1 MasterSlide#{0} is equal to SomePresentation2 MasterSlide#{1}", i, j)); | |
else Console.Write("slides are not same"); | |
} | |
} | |
} |
Retrieve PowerPoint Slide properties programmatically in C#
In addition, you may configure your API calls to meet your business requirements. This C# PowerPoints library comes up with a wide range of methods that you may check here.
However, you may follow the steps and the code snippet mentioned below:
- Get info about the presentation in the specified file by calling the GetPresentationInfo method.
- Invoke the ReadDocumentProperties method to get the document properties of the binded presentation.
- Assign the document properties to the object of the IDocumentProperties.
- CreatedTime property will let you know about the date when a presentation was created.
- You can retrieve the subject of the PPTX file by accessing Subject property.
- Title property will extract the title information.
// Get info about presentation in specified file by calling the GetPresentationInfo method | |
IPresentationInfo info = PresentationFactory.Instance.GetPresentationInfo("sample.pptx"); | |
// Invoke the ReadDocumentProperties method to get document properties of binded presentation. | |
// Assign the document properties to the object of the IDocumentProperties. | |
IDocumentProperties props = info.ReadDocumentProperties(); | |
// CreatedTime property will let you know about the date when a presentation was created. | |
Console.WriteLine(props.CreatedTime); | |
// You can retrieve the subject of PPTX file by accessing Subject property | |
Console.WriteLine(props.Subject); | |
// Title property will extract the title information | |
Console.WriteLine(props.Title); |
Get a Free License
You can avail of a free temporary license to try the API without evaluation limitations.
Summing up
We may end this blog post here. We have demonstrated how to compare two PowerPoint files in C# programmatically. Above all, we also have gone through some advanced methods exposed by this C# PowerPoint library. Further, you may visit documentation to learn about other methods. Finally, please visit conholdate.com for the latest updates.
Ask a question
You can let us know about your questions or queries on our forum.
FAQs
How do you compare two presentations and merge results in PowerPoint?
You can install this C# PowerPoint library to compare two PPTX files programmatically. Further, you may visit this link to know the code snippet.