Today, we will provide password protection to our presentation files programmatically. Previously, we learned something similar while discussing password protection of PDF files in C#. In this article, we will see how to lock PowerPoint presentation files with password protection in C#. Further, we will learn to unlock these by removing the password and also how to change the existing password of PPT & PPTX presentation files.
The following topics are discussed below:
- .NET API to Protect PowerPoint PPT/PPTX with Password
- Lock PowerPoint Files by adding Password
- Change PPT/PPTX Password in C#
- How to Remove PowerPoint Presentation Password
.NET API to Lock and Unlock PowerPoint Files
To work with the protection of presentation files, we will use GroupDocs.Merger for .NET. This API allows adding, changing, and removing password security features for the presentation and other documents within the .NET applications. Along with the locking and unlocking PPT files, the API provides many more features including merging and splitting presentations that are mentioned in the documentation.
You can download the DLLs or MSI installer from the downloads section or install the API in your .NET application via NuGet.
PM> Install-Package GroupDocs.Merger
Add Password to PowerPoint Files in C# – Lock PPT/PPTX
We can programmatically lock any presentation file by adding password protection to it. The following steps show how to add a password to a PowerPoint presentation (PPT/PPTX) using C#.
- Define the password using the AddPasswordOptions.
- Load the PowerPoint file using the Merger class.
- Apply protection by adding password using AddPassword method.
- Save the protected presentation file using the Save method.
The following C# code snippet locks the PPT by adding a password for limited access.
Here is the output of the above code. When you try to open the file, the editor or viewer will ask for the password to open the presentation.
Update Existing Password of PPT/PPTX Files in C#
Looks like there was a sneak peek at your password. Let’s change it. The following steps allow you to change the existing presentation file password using C#.
- Prepare the loading options using the current password.
- Prepare the update options using the new password.
- Load the presentation using Merger class.
- Change the password using the UpdatePassword method.
- Call Save method to save the locked file having new password.
Here is the code snippet that changes the existing password of a PowerPoint PPT/PPTX presentation.
Remove PowerPoint File Password in C# – Unlock PPT/PPTX
Now let’s remove the cover and let everyone benefit from your presentation. First, open the file and then remove its password for easy access. The following steps show how to unlock the PPT file by removing its password using C#.
- Use file’s password to prepare the loading options.
- Load the PowerPoint presentation document using Merger class.
- Remove the password using RemovePassword method.
- Save the unlocked file using the Save method.
The following C# code sample unlocks the PowerPoint presentation file by removing its password.
Conclusion
Let’s conclude with an overview of what we learned today. We used a simple PowerPoint presentation (PPTX) and first, we locked it just by adding a password. Next, we changed the existing password of the presentation file. Lastly, we learned how to remove the password of the PowerPoint presentations.
To learn more about GroupDocs.Merger for .NET, visit the documentation and start building your own application to lock and unlock presentation files. For queries, contact us via the forum.
Get a Free API License
You can get a free temporary license to use the API without the evaluation limitations.