CSOM: Working with Office365 Project Online Tasks - Part I

Updated: Mar 22, 2019

This article series focuses on working with office 365 project online plan schedule tasks using Client Side Object model approach.

Previously we have seen how the same operations works using JSOM approach. Both approaches are identical.

Creating Console App and Importing Package: 

SharePoint and Project Server online libraries are required to work with the project server data using CSOM model. The libraries can be downloaded from Nuget packages. The required libraries are packaged under one single package. i.e., Microsoft.SharePointOnline.CSOM

Create a visual studio console application. From Tools -> Nuget Package Manager -> Manage Nuget Packages for Solution. From the browse tab, Find for “Microsoft.SharePointOnline.CSOM”. Select and install the package for the current solution.

The following picture depicts installing the required Nuget package.

Installing Nuget Packages for SharePoint & Project Online

Retrieve All Tasks: 

First let us look at retrieving all the tasks available on the project. There are two ways of retrieving tasks.

1. From the published project object – Advantage is project need not be checked-out. Since this is read only action, the tasks can be accessed this way.

  1. using (ProjectContext projContext = new ProjectContext("https://nakkeerann.sharepoint.com/sites/pwa"))

  2. {

  3. projContext.Credentials = new SharePointOnlineCredentials("nav@nakkeerann.onmicrosoft.com", password);

  4. var projects = projContext.Projects;

  5. // Specific Project ID

  6. var projectId = "3a000b01-55f2-e811-afac-00155d24c70d";

  7. var project = projects.GetById(projectId);

  8. var tasks = project.Tasks; projContext.Load(tasks);

  9. projContext.ExecuteQuery();

  10. foreach (var task in tasks)

  11. {

  12. Console.WriteLine(task.Name);

  13. }}

2. Other way from the draft project – Trying to retrieve after checking out the project. Don’t prefer this approach if you are just viewing/accessing tasks.

  1. private static void ViewTasksFromCheckedOutProject()