Project Server and Project Online in C# ASP.NET

The Project Online and Project Server are the feature-rich project and portfolio management solutions provided by Microsoft. Both the solutions offer almost a similar range of features for creating and managing projects, however, they differ based on which solution fits well with your requirements. For example, if you want the on-premise solution with more control over the hardware and software then you may opt Project Server. On the other hand, Project Online serves as a cloud-based instance of Project Server without requiring your own infrastructure.

There might be the case when to need to access the information of the projects from Project Server/Online from within your applications. In order to deal with such cases, in this article, I’ll show you how to create/read the projects on/from Project Server or Project Online within your .NET applications (ASP.NET, etc.) or web services using C#.

C# API for Project Server/Online

For creating the new projects and reading the existing ones from Project Server/Online, we’ll use Aspose.Tasks for .NET. It is a cross-platform class library for reading and writing MS Project files programmatically in .NET Standard or .NET Core applications. The API is hosted on NuGet as well as available as an MSI package and zipped DLL in the Downloads section.

Working with Project Server

In this section, I’ll show you how to connect to the Project Server and read or create the projects. In order to connect to the Project Server, you need to know the following details:

Read Projects from Project Server in C#

The following are the steps to connect to Project Server and retrieve the projects list from it.

The following code sample shows how to read projects from Project Server in C#.

string url = "https://contoso.sharepoint.com";
string domain = "CONTOSO.COM";
string userName = "Administrator";
string password = "MyPassword";
NetworkCredential windowsCredentials = new NetworkCredential(userName, password, domain);
ProjectServerCredentials projectServerCredentials = new ProjectServerCredentials(url, windowsCredentials);
ProjectServerManager manager = new ProjectServerManager(projectServerCredentials);
var list = manager.GetProjectList();
foreach (var projectInfo in list)
{
Console.WriteLine("{0} - {1} - {2}", projectInfo.Id, projectInfo.CreatedDate, projectInfo.Name);
}

Create Project on Project Server in C#

Creating a project on Project Server is as simple as pie. Simply connect to Project Server in the same way you have done in the previous example, load the project file (.mpp) using Project class and call ProjectServerManager.CreateNewProject() method.

The following code sample shows how to create a new project on Project Server in C#.

Project project = new Project("New Project.mpp");
NetworkCredential windowsCredentials = new NetworkCredential("Administrator", "MyPassword", "CONTOSO.COM");
ProjectServerCredentials projectServerCredentials = new ProjectServerCredentials("https://contoso.sharepoint.com", windowsCredentials);
ProjectServerManager manager = new ProjectServerManager(projectServerCredentials);
manager.CreateNewProject(project);

Working with Project Online

Working with Project Online is quite similar to working with Project Server and it only differs in creating the connection. In order to connect to Project Online, you need to know the following details:

  • URL
  • Username
  • Password

Read Projects from Project Online in C#

The following are the steps to read projects from Project Online:

The following code sample shows how to retrieve the list of projects from Project Online.

const string SharepointDomainAddress = "https://contoso.sharepoint.com";
const string UserName = "admin@contoso.onmicrosoft.com";
const string Password = "MyPassword";
ProjectServerCredentials credentials = new ProjectServerCredentials(SharepointDomainAddress, UserName, Password);
ProjectServerManager manager = new ProjectServerManager(credentials);
IEnumerable<ProjectInfo> list = manager.GetProjectList();
foreach (var info in list)
{
Project project = manager.GetProject(info.Id);
Console.WriteLine("{0} - {1} - {2}", info.Name, info.CreatedDate, info.LastSavedDate);
Console.WriteLine("Resources count: {0}", project.Resources.Count);
// an user can read the project as raw data stream
var stream = manager.GetProjectRawData(info.Id);
// work with raw project data
}

Create a Project on Project Online in C#

The following are the steps to create a new project on Project Online:

The following code sample shows how to create a new project on Project Online in C#.

string sharepointDomainAddress = "https://contoso.sharepoint.com";
string userName = "admin@contoso.onmicrosoft.com";
string password = "MyPassword";
ProjectServerCredentials credentials = new ProjectServerCredentials(sharepointDomainAddress, userName, password);
Project project = new Project("New Project.mpp");
ProjectServerManager manager = new ProjectServerManager(credentials);
manager.CreateNewProject(project);

Learn more about Aspose.Tasks for .NET

You can learn more about project management using Aspose.Tasks for .NET from the documentation.