Reading and Saving Projects in Project Server or Project Online

Aspose.Tasks for .NET provides full support for working with Project Server (on-premises) and Project Online (cloud-based) by leveraging the Project Web Access (PWA) API. This enables developers to programmatically create, read, and update projects stored in enterprise project management environments.

Such integration is useful for organizations that rely on centralized project repositories and want to automate processes such as bulk updates, scheduled reporting, or project synchronization without requiring manual interaction in Microsoft Project or Project Web App.

Managing Projects with Project Server

Aspose.Tasks for .NET introduces the ProjectServerManager class to connect to Project Server or Project Online. For authentication, use the ProjectServerCredentials class, which now allows specifying the SiteUrl, Username, and Password directly. Previously, developers had to use the Microsoft.SharePoint.Client.Runtime assembly to retrieve an AuthToken, but this dependency is no longer required.

Note: Currently, Aspose.Tasks for .NET does not support modern authentication for Project Online.
Legacy authentication must be enabled in your Azure portal and Office 365 Admin Center for successful integration.

Reading Project from Project Server

The following example shows how to connect to Project Server and read an existing project’s data:

 1const string SharepointDomainAddress = "https://contoso.sharepoint.com";
 2const string UserName = "admin@contoso.onmicrosoft.com";
 3const string Password = "MyPassword";
 4
 5ProjectServerCredentials credentials = new ProjectServerCredentials(SharepointDomainAddress, UserName, Password);
 6ProjectServerManager manager = new ProjectServerManager(credentials);
 7IEnumerable<ProjectInfo> list = manager.GetProjectList();
 8
 9foreach (var info in list)
10{
11    Project project = manager.GetProject(info.Id);
12    Console.WriteLine("{0} - {1} - {2}", info.Name, info.CreatedDate, info.LastSavedDate);
13    Console.WriteLine("Resources count: {0}", project.Resources.Count);
14
15    // an user can read the project as raw data stream
16    var stream = manager.GetProjectRawData(info.Id);
17
18    // work with raw project data
19}

Creating a Project in Project Server

This example demonstrates how to create a new project in Project Server programmatically:

 1try
 2{
 3    const string SharepointDomainAddress = "https://contoso.sharepoint.com";
 4    const string UserName = "admin@contoso.onmicrosoft.com";
 5    const string Password = "MyPassword";
 6
 7    ProjectServerCredentials credentials = new ProjectServerCredentials(SharepointDomainAddress, UserName, Password);
 8
 9    Project project = new Project("New Project.mpp");
10
11    ProjectServerManager manager = new ProjectServerManager(credentials);
12    manager.CreateNewProject(project);
13}
14catch (ProjectOnlineException ex)
15{
16    Console.WriteLine(ex.Message);
17}

You can also create a project in Project Online with predefined save options:

1Project project = new Project("New Project.mpp");
2ProjectServerCredentials credentials = new ProjectServerCredentials("https://contoso.sharepoint.com", "admin@contoso.onmicrosoft.com", "MyPassword");
3ProjectServerManager manager = new ProjectServerManager(credentials);
4ProjectServerSaveOptions options = new ProjectServerSaveOptions
5{
6    Timeout = TimeSpan.FromSeconds(10)
7};
8manager.CreateNewProject(project, options);

Updating a Project in Project Server

This example demonstrates how to update an existing project in Project Server:

 1const string URL = "https://contoso.sharepoint.com";
 2const string Domain = "CONTOSO.COM";
 3const string UserName = "Administrator";
 4const string Password = "MyPassword";
 5
 6NetworkCredential windowsCredentials = new NetworkCredential(UserName, Password, Domain);
 7ProjectServerCredentials projectServerCredentials = new ProjectServerCredentials(URL, windowsCredentials);
 8try
 9{
10    ProjectServerManager manager = new ProjectServerManager(projectServerCredentials);
11
12    var projectInfo = manager.GetProjectList().FirstOrDefault(p => p.Name == "My project");
13    if (projectInfo == null)
14    {
15        Console.WriteLine("Project 'My project' not found in working store of Project Online account.");
16        return;
17    }
18
19    Project project = manager.GetProject(projectInfo.Id);
20    project.Set(Prj.FinishDate, new DateTime(2020, 03, 01));
21
22    Task task = project.RootTask.Children.Add("New task");
23    task.Set(Tsk.Start, new DateTime(2020, 02, 26));
24    task.Set(Tsk.Duration, project.GetDuration(2, TimeUnitType.Day));
25
26    manager.UpdateProject(project);
27}
28catch (ProjectOnlineException ex)
29{
30    Console.WriteLine("Failed to update the project. Error: " + ex);
31}

You can also update projects in Project Online with save options, giving you greater control over how changes are applied:

 1const string SharepointDomainAddress = "https://contoso.sharepoint.com";
 2const string UserName = "admin@contoso.onmicrosoft.com";
 3const string Password = "MyPassword";
 4
 5ProjectServerCredentials credentials = new ProjectServerCredentials(SharepointDomainAddress, UserName, Password);
 6
 7try
 8{
 9    ProjectServerManager manager = new ProjectServerManager(credentials);
10
11    var projectInfo = manager.GetProjectList().FirstOrDefault(p => p.Name == "My project");
12    if (projectInfo == null)
13    {
14        Console.WriteLine("Project 'My project' not found in working store of Project Online account.");
15        return;
16    }
17
18    Project project = manager.GetProject(projectInfo.Id);
19    project.Set(Prj.FinishDate, new DateTime(2020, 03, 01));
20
21    Task task = project.RootTask.Children.Add("New task");
22    task.Set(Tsk.Start, new DateTime(2020, 02, 26));
23    task.Set(Tsk.Duration, project.GetDuration(2, TimeUnitType.Day));
24
25    ProjectServerSaveOptions options = new ProjectServerSaveOptions { Timeout = TimeSpan.FromMinutes(5) };
26
27    manager.UpdateProject(project, options);
28}
29catch (ProjectOnlineException ex)
30{
31    Console.WriteLine("Failed to update the project. Error: " + ex);
32}

By using Aspose.Tasks for .NET, developers can seamlessly integrate with both Project Server and Project Online. This allows creating, reading, and updating enterprise projects programmatically, making it easier to maintain consistency, automate workflows, and integrate project data into larger business systems. Such automation helps reduce manual effort, improve accuracy, and ensure that enterprise-level project management remains synchronized and efficient.

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.