Update Project Details Using CSOM Project Online

Update Project Details Using CSOM Project Online

Update Project Details Using CSOM Project Online. In this post, I am writing code for Update Project Details Using CSOM. The project created by Project Manager with project detail like project description, project creation date, Project Owner Name etc. So here you get the code to update project details using CSOM. In my previous post, I explained Create Project using CSOM.[AdSense-A]

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security;
using Microsoft.ProjectServer.Client;
using Microsoft.SharePoint.Client;
using PRCLNT = Microsoft.ProjectServer.Client;

namespace UpdateProjectDetials_Using_CSOM
{
    class Program
    {
        static string UserName = "UserName";
        static string Passwords = "Password";
        public static string OnlinePWA = "PWAPath";
        static void Main(string[] args)
        {
            using (PRCLNT.ProjectContext ProjectCont = new PRCLNT.ProjectContext(OnlinePWA))//PWA Url
            {
                SecureString passWord4 = new SecureString();
                foreach (char c in Passwords.ToCharArray()) passWord4.AppendChar(c);
                ProjectCont.Credentials = new SharePointOnlineCredentials(UserName, passWord4);
                var projCollection = ProjectCont.LoadQuery(ProjectCont.Projects.Where(p => p.Name == "Project Name"));
                ProjectCont.ExecuteQuery();
                PublishedProject proj2Edit = projCollection.First();
                DraftProject projCheckedOut = proj2Edit.CheckOut();
                ProjectCont.Load(projCheckedOut);
                ProjectCont.ExecuteQuery();
                projCheckedOut.Name = "Project Name";
                projCheckedOut.Description = "This content updated by ProjectServercode..";
                projCheckedOut.SetCustomFieldValue("Custom_5fff1dcb-90e2-e411-80c5-00155dkdab0f", "CustomFieldValue");
                projCheckedOut.Update();
                ProjectCont.Load(projCheckedOut);
                ProjectCont.ExecuteQuery();
                ProjectCont.Projects.Update();
                ProjectCont.ExecuteQuery();
                projCheckedOut.Publish(true);
                JobState jobState = ProjectCont.WaitForQueue(ProjectCont.Projects.Update(), 10);
            }
        }
    }
}

 


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!