Working with Password Protected Projects

Microsoft Project allows users to add password protection when saving a project in MPP format:

Save options in Save dialog in Microsoft Project

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

  1. 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

  1. 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:

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.
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.