Working with Password Protected Projects
Microsoft Project allows users to add password protection when saving a project in MPP format:
This article demonstrates how Aspose.Tasks for .NET can be used to work with password-protected projects in MPP format.
Read Password Protected Projects
The Project class exposes the Project() constructor overloads which allows to read password-protected MPP files.
To read a password-protected project file you can either
- Use a Project(string, string) constructor overload and pass the password as a second argument:
1 Project project = new Project("New Project.mpp", "password");
Or
- Use a Project(string, LoadOptions) constructor overload in the following way:
1 Project project = new Project("New Project.mpp", new LoadOptions { Password = "password" } );
You can also check whether a project file is password protected:
1 var info = Project.GetProjectFileInfo("PasswordProtected.mpp");
2 Console.WriteLine("Is file password protected?:" + info.IsPasswordProtected);
Add Password Protection
Aspose.Tasks for .NET can also add password protection when saving a project in MPP format.
Keep in mind the following restrictions:
- Adding a protection password is supported for projects saved by Microsoft Project 2010 and later.
- Currently only protection password is supported. Write reservation password will be available in a future release.
The following snippet demonstrates how to add a protection password:
1 Project project = new Project("Test project.mpp");
2 project.Save("output_protected.mpp",
3 new MPPSaveOptions()
4 {
5 ProtectionPassword = "password"
6 });
Note: Once a password-protected project is saved without specifying the ProtectionPassword
, it becomes unprotected.
1 Project project = new Project("ProtectedFile", "password");
2
3 project.Save("output.mpp", SaveFileFormat.MPP);
4 // output.mpp file is not protected
5
6 project.Save("output_protected.mpp", new MPPSaveOptions()
7 {
8 ProtectionPassword = "password"
9 });
10
11 // output_protected.mpp file is protected.