
The document properties or metadata in PowerPoint files are used for identification of the presentations. Moreover, they provide additional information about the presentation such as author, title, keywords, subject, etc. In this article, you will learn how to access or modify the properties in PowerPoint files programmatically using C#.
- .NET API to Access/Modify Properties in PowerPoint PPT
- Types of Properties in PowerPoint PPT
- Access Built-in Properties in PowerPoint PPTX
- Modify Built-in Properties in PowerPoint PPT
- Add Custom Properties in PowerPoint PPT
- Access Custom Properties in PowerPoint PPTX
- Modify Custom Properties in PowerPoint PPTX
C# API to Access/Modify Properties in PowerPoint PPT
To access or modify the built-in or custom document properties, we will use Aspose.Slides for .NET. It is a powerful API for creating and manipulating PowerPoint and OpenOffice documents. The API is available as a downloadable DLL as well as on NuGet.
PM> Install-Package Aspose.Slides.NET
Types of Properties in PowerPoint Presentations
The PowerPoint presentations support two types of document properties: built-in and custom. The built-in properties provide general information about the presentations such as title, author, subject, etc. Whereas, the custom properties are defined by the users in the form of key/value pairs. The following sections demonstrate how to add, access, and modify properties belonging to each of the above-mentioned types.
Access Built-in Properties in PowerPoint PPT using C#
The following are the steps to access the built-in properties in PowerPoint presentations using C#.
- Load the PowerPoint presentation using Presentation class.
- Access the built-in properties in an IDocumentProperties object from Presentation.DocumentProperties property.
- Read each built-in property in the presentation using IDocumentProperties object, such as, IDocumentProperties.Author.
The following code sample shows how to access built-in properties in PowerPoint presentations.
Modify Built-in Properties in PowerPoint PPTX using C#
The following are the steps to modify the values of the built-in properties in PowerPoint PPT using C#.
- First, load the PowerPoint presentation using Presentation class.
- Then, get reference of the built-in properties in an IDocumentProperties object from Presentation.DocumentProperties property.
- Modify the desired built-in property in the presentation using IDocumentProperties object, such as, IDocumentProperties.Author.
- Finally, save the presentation using Presentation.Save(String, SaveFormat) method.
The following code sample shows how to modify the built-in properties in PowerPoint PPT in C#.
Add Custom Properties in PowerPoint PPT using C#
The following are the steps to add custom properties in a PowerPoint presentation using C#.
- First, load the PowerPoint presentation using Presentation class.
- Then, get reference of the document properties in an IDocumentProperties object from Presentation.DocumentProperties property.
- Add a custom property by defining its key and value, e.g. IDocumentProperties[“Key”] = “Value”.
- Finally, save the presentation using Presentation.Save(String, SaveFormat) method.
The following code sample shows how to add custom properties in a PowerPoint PPT in C#.
Access Custom Properties in PowerPoint PPTX using C#
The following steps demonstrate how to access the custom properties in a PowerPoint Presentation using C#.
- First, load the PowerPoint presentation using Presentation class.
- Get reference of the document properties in an IDocumentProperties object from Presentation.DocumentProperties property.
- Access each custom property using IDocumentProperties.GetCustomPropertyName(int32 index) method in a loop.
The following code sample shows how to access custom properties in a PowerPoint PPT.
Modify Custom Properties in PowerPoint PPT using C#
The following are the steps to modify the custom properties in a PowerPoint PPTX in C#.
- First, load the PowerPoint presentation using Presentation class.
- Then, get reference of the document properties in an IDocumentProperties object from Presentation.DocumentProperties property.
- Access each custom property using IDocumentProperties.GetCustomPropertyName(int32 index) method in a loop.
- Modify the value of a property by specifying its key in IDocumentProperties[IDocumentProperties.GetCustomPropertyName(int index)] array.
- Finally, save the presentation using Presentation.Save(String, SaveFormat) method.
The following C# code sample shows how to modify a custom property in a PowerPoint PPTX.
C# .NET PowerPoint API - Get a Free License
You can use Aspose.Slides for .NET without evaluation limitations by requesting a temporary license.
Manipulate PPT Properties - Online Demo
You can also try the online tool to view and edit document properties in presentations, which is based on Aspose.Slides.
You may also want to try out Aspose free online PowerPoint editor.
Conclusion
In this article, you have learned how to add, access, and modify document properties in PowerPoint PPT/PPTX using C#. The article has covered the manipulation of built-in and custom document properties explicitly. In addition, you can visit the documentation to explore more about Aspose.Slides for .NET. Also, you can post your queries to our forum.