Презентация на 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.