Remove Resource from Project Team using CSOM

Remove Resource from Project Team using CSOM

Remove Resource from Project Team using CSOM. In this post, I am trying to Remove the resource from Project Team using CSOM. During a project plan, we have to team build for task assignment.In this post, you will learn programmatically Remove the resource from Project Team using CSOM. I have also written code for Add Enterprise Resource to Project Team using CSOM[AdSense-A]

If you don’t know to add references in your solutions then follow the post below

Add  references in Solution

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 RemoveResourceFromProjectTeam_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.ProjectResources);
                ProjectCont.ExecuteQuery();
                foreach (var item in projCheckedOut.ProjectResources)
                {
                    Console.WriteLine("Res Name:" + item.Name + " Id: " + item.Id);
                    if (item.Name == "Resource Name")
                    {
                        projCheckedOut.ProjectResources.Remove(item);
                        break;
                    }
                }
                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 !!