Cách bảo mật bản trình bày PowerPoint trong C# .NET

Bản trình bày PowerPoint có thể được bảo mật theo nhiều cách khác nhau như áp dụng hình nền mờ, thêm chữ ký hoặc đặt ở chế độ chỉ đọc. Trong hướng dẫn từng bước này, chúng tôi sẽ chỉ cho bạn cách bảo mật bản trình bày PowerPoint trong C# .NET bằng mật khẩu.

Aspose.Slides for .NET API giúp bạn bảo mật PowerPoint presentation bằng C# mà không cần Microsoft Interop và không yêu cầu cài đặt Microsoft PowerPoint.

Các bước để bảo mật bản trình bày PowerPoint trong C#

  1. Sử dụng gói NuGet Aspose.Slides for .NET
  2. Thêm tham chiếu vào không gian tên Aspose.SlidesAspose.Slides.Export
  3. Áp dụng giấy phép Aspose với sự trợ giúp của phương pháp SetLicense
  4. Bắt đầu phiên bản Presentation Class
  5. Sử dụng phương thức Mã hóa của lớp ProtectionManager để bảo mật bản trình bày bằng mật khẩu
  6. Cuối cùng, lưu bản trình bày được bảo vệ bằng mật khẩu bằng phương thức Lưu và thuộc tính SaveFormat.Pptx

Mã để bảo mật bản trình bày PowerPoint trong 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);
}
}
}

Trong các bước và mã ở trên, bạn đã học cách bảo mật PPTX bằng C#. API này không giới hạn ở việc bảo vệ bằng mật khẩu, thay vào đó, bạn cũng có thể khóa và mở khóa tệp PPTX trong C#. Điều này làm cho việc bảo mật PPTX bằng C# trở thành một nhiệm vụ rất đơn giản và dễ dàng với sự trợ giúp của Aspose.Slides cho .NET.

 Tiếng Việt