A PowerPoint presentation can be secured in different ways like by applying a watermark, adding signature, or making it read only. In this step by step guide, we’ll show you how to secure PowerPoint presentation in C# .NET using a password.
The Aspose.Slides for .NET API helps you secure PowerPoint presentation using C# without the need for Microsoft Interop and does not require Microsoft PowerPoint to be installed.
Steps to Secure PowerPoint Presentation in C#
- Use Aspose.Slides for .NET NuGet package
- Add reference to Aspose.Slides and Aspose.Slides.Export namespaces
- Apply Aspose license with the help of SetLicense method
- Initiate a Presentation Class instance
- Utilize Encrypt method of ProtectionManager class to secure presentation with a password
- Finally, save password protected presentation using Save method and SaveFormat.Pptx property
Code to Secure PowerPoint Presentation in C#
using System; | |
//Install Aspose.Slides for .NET NuGet package | |
//and then utilize the following namespace to | |
//secure PowerPoint presentation | |
using Aspose.Slides; | |
using Aspose.Slides.Export; | |
namespace SecurePowerPointPresentation | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
//Set Aspose license before securing PowerPoint presentation | |
//using Aspose.Slides for .NET | |
Aspose.Slides.License AsposeSlidesLicense = new Aspose.Slides.License(); | |
AsposeSlidesLicense.SetLicense(@"c:\asposelicense\license.lic"); | |
//create an object of Presentation class from Aspose.Slides namespace | |
//and provide the PowerPoint presentation to secure in the constructor | |
Presentation PowerPointPresentationToSecure = new Presentation("PowerPointPresentationToSecure.pptx"); | |
//specify the password with which you want to secure the presentation | |
//this can be taken as input password from the user/admin etc. | |
String PasswordForPresentationSecurity = "8ma2bzdqgo"; | |
//Encrypt or secure the presentation with the password using Encrypt method | |
//with the help of ProtectionManager | |
PowerPointPresentationToSecure.ProtectionManager.Encrypt(PasswordForPresentationSecurity); | |
//Finally, save the output presentation secured with password | |
//provide PPTX as save format | |
PowerPointPresentationToSecure.Save("PresentationSecuredWithPassword.pptx",Aspose.Slides.Export.SaveFormat.Pptx); | |
} | |
} | |
} |
In the above steps and code, you learned how to secure PPTX using C#. This API is not limited to password protection, rather you can also lock and unlock PPTX file in C# as well. This makes securing PPTX using C# a very simple and easy task with the help of Aspose.Slides for .NET.