By default, anyone who can access a PowerPoint document can open and edit it. If you want to prevent your PowerPoint document from unauthorized viewing or modification, you can protect it with a password. In addition to adding password protection, you can also choose other ways to protect the document, such as marking it as final to discourage editing. When you want to make the document public, you can unprotect it at any time. In this article, we will demonstrate how to protect or unprotect PowerPoint documents in C# and VB.NET using Spire.Presentation for .NET.
- Protect a PowerPoint Document with a Password
- Mark a PowerPoint Document as Final
- Remove Password Protection from a PowerPoint Document
- Remove Mark as Final Option from a PowerPoint Document
Install Spire.Presentation for .NET
To begin with, you need to add the DLL files included in the Spire.Presentation for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.Presentation
Protect a PowerPoint Document with a Password in C# and VB.NET
You can protect a PowerPoint document with a password to ensure that only the people who have the right password can view and edit it.
The following steps demonstrate how to protect a PowerPoint document with a password:
- Initialize an instance of Presentation class.
- Load a PowerPoint document using Presentation.LoadFromFile() method.
- Encrypt the document with a password using Presentation.Encrypt() method.
- Save the result document using Presentation.SaveToFile() method.
- C#
- VB.NET
using Spire.Presentation; namespace ProtectPPTWithPassword { class Program { static void Main(string[] args) { //Create a Presentation instance Presentation presentation = new Presentation(); //Load a PowerPoint document presentation.LoadFromFile(@"Sample.pptx"); //Encrypt the document with a password presentation.Encrypt("your password"); //Save the result document presentation.SaveToFile("Encrypted.pptx", FileFormat.Pptx2013); } } }
Mark a PowerPoint Document as Final in C# and VB.NET
You can mark a PowerPoint document as final to inform readers that the document is final and no further editing is expected.
The following steps demonstrate how to mark a PowerPoint document as final:
- Initialize an instance of Presentation class.
- Load a PowerPoint document using Presentation.LoadFromFile() method.
- Mark the document as final through Presentation.DocumentProperty[] property.
- Save the result document using Presentation.SaveToFile() method.
- C#
- VB.NET
using Spire.Presentation; namespace MarkPPTAsFinal { class Program { static void Main(string[] args) { //Create a Presentation instance Presentation ppt = new Presentation(); //Load a PowerPoint document ppt.LoadFromFile(@"Sample.pptx"); //Mark the document as final ppt.DocumentProperty["_MarkAsFinal"] = true; //Save the result document ppt.SaveToFile("MarkAsFinal.pptx", FileFormat.Pptx2013); } } }
Remove Password Protection from a PowerPoint Document in C# and VB.NET
You can remove password protection from a PowerPoint document by loading the document with the correct password, then removing the password protection from it.
The following steps demonstrate how to remove password protection from a PowerPoint document:
- Initialize an instance of Presentation class.
- Load a PowerPoint document using Presentation.LoadFromFile() method.
- Mark the document as final through Presentation.RemoveEncryption() method.
- Save the result document using Presentation.SaveToFile() method.
- C#
- VB.NET
using Spire.Presentation; namespace RemovePasswordProtectionFromPPT { class Program { static void Main(string[] args) { //Create a Presentation instance Presentation presentation = new Presentation(); //Load a password-protected PowerPoint document with the right password presentation.LoadFromFile(@"Encrypted.pptx", "your password"); //Remove password protection from the document presentation.RemoveEncryption(); //Save the result document presentation.SaveToFile("RemoveProtection.pptx", FileFormat.Pptx2013); } } }
Remove Mark as Final Option from a PowerPoint Document in C# and VB.NET
The mark as final feature makes a PowerPoint document read-only to prevent further changes, if you decide to make changes to the document later, you can remove the mark as final option from it.
The following steps demonstrate how to remove mark as final option from a PowerPoint document:
- Initialize an instance of Presentation class.
- Load a PowerPoint document using Presentation.LoadFromFile() method.
- Mark the document as final through Presentation.DocumentProperty[] property.
- Save the result document using Presentation.SaveToFile() method.
- C#
- VB.NET
using Spire.Presentation; namespace RemoveMarkAsFinalFromPPT { class Program { static void Main(string[] args) { //Create a Presentation instance Presentation ppt = new Presentation(); //Load a PowerPoint document ppt.LoadFromFile(@"MarkAsFinal.pptx"); //Remove mark as final option from the document ppt.DocumentProperty["_MarkAsFinal"] = false; //Save the result document ppt.SaveToFile("RemoveMarkAsFinal.pptx", FileFormat.Pptx2013); } } }
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.