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.
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.
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.
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.
The following code snippet shows retrieving tasks, but with minimal load. It gets only the properties mentioned in the load query.
Let's see, how a particular task can be retrieved. Task ID can be used to retrieve one particular task. And necessary properties can be accessed after retrieval. The following piece of code shows, retrieving a task by project ID and task ID. And it also shows the properties (including custom) accessed.
In the next article, let us look at more other operations for MSP project online tasks.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using (ProjectContext projContext = new ProjectContext("https://nakkeerann.sharepoint.com/sites/pwa")) | |
{ | |
projContext.Credentials = new SharePointOnlineCredentials("nav@nakkeerann.onmicrosoft.com", password); | |
var projects = projContext.Projects; | |
// Specific Project ID | |
var projectId = "3a000b01-55f2-e811-afac-00155d24c70d"; | |
var project = projects.GetById(projectId); | |
var tasks = project.Tasks; | |
projContext.Load(tasks); | |
projContext.ExecuteQuery(); | |
foreach (var task in tasks) | |
{ | |
Console.WriteLine(task.Name); | |
} | |
} |
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void ViewTasksFromCheckedOutProject() | |
{ | |
using (ProjectContext projContext = new ProjectContext("https://nakkeerann.sharepoint.com/sites/pwa")) | |
{ | |
projContext.Credentials = new SharePointOnlineCredentials("nav@nakkeerann.onmicrosoft.com", password); | |
var projects = projContext.Projects; | |
var projectId = "3a000b01-55f2-e811-afac-00155d24c70d"; | |
var project = projects.GetById(projectId); | |
// If the project is already checked out, comment the below line | |
var draftProject = project.CheckOut(); | |
// If not already checked out, uncomment the below line | |
//var draftProject = project.Draft; | |
var tasks = draftProject.Tasks; | |
projContext.Load(draftProject); | |
projContext.Load(tasks); | |
projContext.ExecuteQuery(); | |
foreach (var task in tasks) | |
{ | |
Console.WriteLine(task.Name); | |
} | |
// Check-In if required | |
} | |
} |
The following code snippet shows retrieving tasks, but with minimal load. It gets only the properties mentioned in the load query.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void ViewTasksMinimal() | |
{ | |
using (ProjectContext projContext = new ProjectContext("https://nakkeerann.sharepoint.com/sites/pwa")) | |
{ | |
projContext.Credentials = new SharePointOnlineCredentials("nav@nakkeerann.onmicrosoft.com", password); | |
var projects = projContext.Projects; | |
var projectId = "3a000b01-55f2-e811-afac-00155d24c70d"; | |
var project = projects.GetById(projectId); | |
var tasks = project.Tasks; | |
// Mention the required properties for access. Only these properties will be retrieved on execution | |
projContext.Load(tasks, properties => properties.Include(property => property["Name"], property => property["Custom_0652e0806606e911afb600155d48510a"])); | |
projContext.ExecuteQuery(); | |
foreach (var task in tasks) | |
{ | |
Console.WriteLine(task.Name); | |
Console.WriteLine(task["Custom_0652e0806606e911afb600155d48510a"]); | |
} | |
} | |
} |
Retrieve Task:
Let's see, how a particular task can be retrieved. Task ID can be used to retrieve one particular task. And necessary properties can be accessed after retrieval. The following piece of code shows, retrieving a task by project ID and task ID. And it also shows the properties (including custom) accessed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void ViewTaskById() | |
{ | |
using (ProjectContext projContext = new ProjectContext("https://nakkeerann.sharepoint.com/sites/pwa")) | |
{ | |
projContext.Credentials = new SharePointOnlineCredentials("nav@nakkeerann.onmicrosoft.com", password); | |
var projects = projContext.Projects; | |
var projectId = "3a000b01-55f2-e811-afac-00155d24c70d"; | |
var project = projects.GetById(projectId); | |
var tasks = project.Tasks; | |
var taskId = "4709f408-55f2-e811-afa6-a01d710bba4a"; | |
// Gets particular Task | |
var task = tasks.GetById(taskId); | |
projContext.Load(task); | |
projContext.ExecuteQuery(); | |
Console.WriteLine(task.Name); | |
Console.WriteLine(task["Custom_0652e0806606e911afb600155d48510a"]); | |
} | |
} |
In the next article, let us look at more other operations for MSP project online tasks.