如何在 C# .NET 中保护 PowerPoint 演示文稿

可以通过不同方式保护 PowerPoint 演示文稿,例如应用水印、添加签名或使其只读。在本分步指南中,我们将向您展示如何使用密码保护 C# .NET 中的 PowerPoint 演示文稿。

Aspose.Slides for .NET API 可帮助您使用 C# 保护 PowerPoint presentation,无需 Microsoft Interop,也无需安装 Microsoft PowerPoint。

在 C# 中保护 PowerPoint 演示文稿的步骤

  1. 使用 Aspose.Slides for .NET NuGet 包
  2. 添加对 Aspose.SlidesAspose.Slides.Export 命名空间的引用
  3. 借助 SetLicense 方法应用 Aspose 许可证
  4. 启动 Presentation Class 实例
  5. 利用 ProtectionManager 类的 Encrypt 方法使用密码保护演示文稿
  6. 最后,使用 Save 方法和 SaveFormat.Pptx 属性保存受密码保护的演示文稿

用 C# 保护 PowerPoint 演示文稿的代码

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);
}
}
}

在上述步骤和代码中,您学习了如何使用 C# 保护 PPTX。此 API 不仅限于密码保护,您还可以在 C# 中锁定和解锁 PPTX 文件。在 Aspose.Slides for .NET 的帮助下,这使得使用 C# 保护 PPTX 成为一项非常简单易行的任务。

 简体中文