Презентация PowerPoint может быть защищена различными способами, например путем применения водяного знака, добавления подписи или предоставления доступа только для чтения. В этом пошаговом руководстве мы покажем вам, как защитить презентацию PowerPoint на C# .NET с помощью пароля.
Aspose.Slides for .NET API помогает защитить PowerPoint presentation с помощью C# без использования Microsoft Interop и установки Microsoft PowerPoint.
Шаги по защите презентации PowerPoint на C#
- Используйте Aspose.Slides for .NET пакет NuGet
- Добавить ссылку на пространства имен Aspose.Slides и Aspose.Slides.Export
- Применить лицензию Aspose с помощью метода SetLicense
- Инициировать экземпляр Presentation Class
- Используйте метод Encrypt класса ProtectionManager для защиты презентации с помощью пароля.
- Наконец, сохраните защищенную паролем презентацию, используя метод Save и свойство SaveFormat.Pptx.
Код для защиты презентации PowerPoint на 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); | |
} | |
} | |
} |
В приведенных выше шагах и коде вы узнали, как защитить PPTX с помощью C#. Этот API не ограничивается защитой паролем, вы также можете блокировать и разблокировать файл PPTX на C#. Это делает защиту PPTX с помощью C# очень простой и легкой задачей с помощью Aspose.Slides для .NET.