Une présentation PowerPoint peut être sécurisée de différentes manières, par exemple en appliquant un filigrane, en ajoutant une signature ou en la rendant en lecture seule. Dans ce guide étape par étape, nous vous montrerons comment sécuriser une présentation PowerPoint en C# .NET à l’aide d’un mot de passe.
Le Aspose.Slides for .NET API vous aide à sécuriser PowerPoint presentation à l’aide de C# sans avoir besoin de Microsoft Interop et ne nécessite pas l’installation de Microsoft PowerPoint.
Étapes pour sécuriser la présentation PowerPoint en C#
- Utiliser le package NuGet Aspose.Slides for .NET
- Ajouter une référence aux espaces de noms Aspose.Slides et Aspose.Slides.Export
- Appliquer la licence Aspose à l’aide de la méthode SetLicense
- Lancer une instance Presentation Class
- Utiliser la méthode Encrypt de la classe ProtectionManager pour sécuriser la présentation avec un mot de passe
- Enfin, enregistrez la présentation protégée par mot de passe à l’aide de la méthode Save et de la propriété SaveFormat.Pptx
Code pour sécuriser la présentation PowerPoint en 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); | |
} | |
} | |
} |
Dans les étapes et le code ci-dessus, vous avez appris à sécuriser PPTX à l’aide de C#. Cette API ne se limite pas à la protection par mot de passe, mais vous pouvez également verrouiller et déverrouiller le fichier PPTX en C# également. Cela rend la sécurisation de PPTX à l’aide de C# une tâche très simple et facile avec l’aide de Aspose.Slides pour .NET.