Working with Password Protected Projects

Microsoft Project allows the user to add password protection when saving project in MPP format:

Save options in Save dialog in Microsoft Project

Now consider how Aspose.Tasks for .NET can be used to work with password protected projects saved 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:
1Project project = new Project("New Project.mpp", "password");

Or

  1. Use a Project(string, LoadOptions) constructor overload in the following way:
1Project project = new Project("New Project.mpp", new LoadOptions { Password = "password" } );

The following code example demonstrates how to check if the project file is password protected.

1var info = Project.GetProjectFileInfo("PasswordProtected.mpp");
2Console.WriteLine("Is file password protected?:" + info.IsPasswordProtected);

Add Password Protection

Aspose.Tasks for .NET can add password protection when writing project in MPP format.

The feature is subject to the following restrictions:

The following snippet can be used to add protection password :

1Project project = new Project("Test project.mpp");
2project.Save("output_protected.mpp",
3    new MPPSaveOptions()
4    {
5        ProtectionPassword = "password"
6    });

Please note that once password-protection project is saved using Aspose.Tasks for .NET without specifying the ProtectionPassword, it becomes unprotected. Thus in the example below the output.mpp is not protected.

 1Project project = new Project("ProtectedFile", "password");
 2
 3project.Save("output.mpp", SaveFileFormat.MPP);
 4// output.mpp file is not protected
 5
 6project.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.