Add Enterprise Resource to Project Team using CSOM

Add Enterprise Resource to Project Team using CSOM

Add Enterprise Resource to Project Team using CSOM. In this post, I am trying to Add Enterprise Resource to Project Team using CSOM. During a project plan, we have to team build for task assignment.In this post, you will learn programmatically Add Enterprise Resource to Project Team using CSOM. I have also written code for Remove Resource from Project Team 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 AddEnterpriseResource_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 == "Resource Plan conversion to resource engagemetns"));
                ProjectCont.ExecuteQuery();
                PublishedProject proj2Edit = projCollection.First();
                DraftProject projCheckedOut = proj2Edit.CheckOut();
                ProjectCont.Load(projCheckedOut.ProjectResources);
                ProjectCont.ExecuteQuery();
                ProjectResourceCreationInformation r = new ProjectResourceCreationInformation();
                r.Id = new Guid("fd3faae2-4ca2-e511-80e7-00155d104000");//Enterprise Resource GUID
                r.Name = "Resource Name";
                projCheckedOut.ProjectResources.Add(r);
                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 !!