Get Enterprise Resource using CSOM

Get Enterprise Resource using CSOM

In this post, you will get how to Get Enterprise Resource using CSOM. Enterprise resource is all resource of an enterprise. When you are going to create a project then you can use these resource in your project as a project team. Next post I will describe you how to Team Build. Below is code to Get Enterprise Resource using CSOM.

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

namespace GetEnterpriseResources_Using_CSOM
{
    class Program
    {
        static string UserName = "UserName";
        static string Passwords = "Password";
        public static string OnlinePWA = "PWA Path";
        static void Main(string[] args)
        {
            try
            {
                using (PRCLNT.ProjectContext ProjectCont = new PRCLNT.ProjectContext(OnlinePWA))//PWA Url
                {
                    SecureString passWord2 = new SecureString();
                    foreach (char c in Passwords.ToCharArray()) passWord2.AppendChar(c);
                    ProjectCont.Credentials = new SharePointOnlineCredentials(UserName, passWord2);
                    ProjectCont.Load(ProjectCont.EnterpriseResources);
                    ProjectCont.ExecuteQuery();
                    if (ProjectCont.EnterpriseResources.Count() > 0)
                    {
                        var projectList = ProjectCont.LoadQuery(ProjectCont.EnterpriseResources);
                        ProjectCont.ExecuteQuery();
                        foreach (EnterpriseResource e in projectList)
                        {
                            string ResourceName = e.Name;
                            Guid ResourceID = e.Id;
                        }
                    }
                }
            }
            catch
            {

            }
        }
    }
}

 

Comments

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.