The protection of digital documents is a common concern these days. You don’t want any unauthorized person to change the content of your documents. Therefore, it becomes inevitable to use effective protection mechanisms. Accordingly, in this article, we will show you how to protect PPT/PPTX presentations from within your .NET applications. We will accomplish that by locking the shapes in a PowerPoint PPT or PPTX in C#.
- C# API to Lock Shapes in PowerPoint PPT
- Lock PowerPoint PPT Shapes in C#
- Unlock Shapes in PowerPoint PPT
C# .NET API to Lock Shapes in PowerPoint PPT
To lock and unlock PowerPoint presentations, we will use Aspose.Slides for .NET. The API provides a range of features to create and manipulate PowerPoint presentations. You can either download API’s DLL or install it using NuGet.
PM> Install-Package Aspose.Slides.NET
Lock Shapes in PowerPoint PPT in C#
A PowerPoint presentation may contain a variety of elements such as text, images, audio, etc. Aspose.Slides for .NET takes each element as a Shape or an abject derived from Shape. So, to protect the content of the presentations, we need to lock all their shapes. Aspose.Slides provides appropriate locks for the following types of shapes.
- Auto Shape
- Group Shape
- Connector
- Picture Frame
The following steps show how to lock shapes in a PowerPoint PPT in C#.
- First, load the PPT/PPTX file using Presentation class.
- Then, get slides in the presentation using Presentation.Slides property.
- For each slide, access its shapes using ISlide.Shapes collection.
- For each shape in the collection, perform the following steps:
- Check type of the shape.
- Use appropriate lock according to type of the shape.
- Finally, save the presentation using Presentation.Save(string, SaveFormat) method.
The following code sample shows how to lock shapes in a PowerPoint PPTX using C#.
Unlock PowerPoint Presentations in C#
To unlock the shapes and make them editable, you will need to turn off the locks. Please note that if you have locked the shapes using Aspose.Slides for .NET then you will have to use the same API for unlocking. Unlocking is done by disabling the shape locks and setting their values to false.
The following code sample shows how to unlock shapes in a PPTX file in C#.
Get a Free License
Use Aspose.Slides for .NET without evaluation limitations by getting a free temporary license.
Conclusion
In this article, you have learned how to lock shapes in PowerPoint PPT/PPTX in C#. Furthermore, you have seen how to unprotect the presentations by unlocking their shapes programmatically. Apart from that, you can explore more about Aspose.Slides for .NET by visiting the documentation. Also, you can post your queries to our forum.