How to read latest project baseline modified date using CSOM – Project Online

Hello,

In this blog, I’m gonna show you a way to read the project baseline modified date using CSOM. As part of one of my Project Online integration solution I came across the situation where I need to read Project baseline modified date using CSOM (as we are developing the whole integration solution in the CSOM).

But as we all know CSOM API doesn’t have the property to read the baseline modified date, so finally have referred the Project Online ODATA feed, found Project baseline modified date column in ProjectBaselines dataset,but I would require this value in the CSOM programming. So have sent an ODATA rest API call to ProjectBaselines dataset endpoint using C# Web client.

Below is the code that reads the Project Baseline modified date for the given Project ID.

Hope it helps.


protected void Page_Load(object sender, EventArgs e)
{
var webUri = new Uri("PWAURL/_api/ProjectData/ProjectBaselines()? </span><span>$select=ProjectBaselineModifiedDate&$Filter=ProjectId eq guid'<id>'");
var credentials = new SharePointOnlineCredentials(userName, SecurePassword(password));
var obj = GetList(webUri, credentials);
ProjectBaselineModifiedDate = DateTime.Parse(obj["results"].FirstOrDefault()["ProjectBaselineModifiedDate"].ToString()).ToShortDateString();
Response.Write(ProjectBaselineModifiedDate);
}

public JToken GetList(Uri webUri, ICredentials credentials)
{
using (var client = new WebClient())
{
client.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
client.Credentials = credentials;
client.Headers.Add(HttpRequestHeader.ContentType, "application/json;odata=verbose");
client.Headers.Add(HttpRequestHeader.Accept, "application/json;odata=verbose");
var endpointUri = webUri;
var result = client.DownloadString(endpointUri);
var t = JToken.Parse(result);
return t["d"];
}
}

Dependencies : Micrososft.sharepointOnine.CSOM & JSON.Net.Web Nugets.

Thanks for reading the post. 🙂