Read Custom Field Value Using CSOM in Project Online

Read Custom Field Value Using CSOM:-

Read Custom Field Value Using CSOM in Project Online. In this post, I will explain to you, Read Custom Field Value Using CSOM. In my previous post, i Explained you, How to Create Custom Field Using CSOM. Now I will read custom field value using some programmatically. In this post, i create the code for reading text custom field value. You also can try for the lookup type custom field value.

[AdSense-A]

using System.Linq;
using Microsoft.ProjectServer.Client;
using Microsoft.SharePoint.Client;
using System.Security;

namespace Read_Custom_Field_Value
{
    class Program
    {
        static string UserName = "UserName";
        static string Passwords = "Password";
        public static string OnlinePWA = "PWA Path";
        static void Main(string[] args)
        {

            ReadCustomFieldValue();
        }
        public static void ReadCustomFieldValue()
        {
            using (ProjectContext ProjectCont = new 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.Projects, c => c.IncludeWithDefaultProperties(pr => pr.IncludeCustomFields, pr => pr.IncludeCustomFields.CustomFields));
                ProjectCont.ExecuteQuery();
                ProjectCont.ExecuteQuery();
                foreach (PublishedProject item in ProjectCont.Projects)
                {
                    if (item.Name == "Project Name")
                    {
                        foreach (var cust in item.IncludeCustomFields.FieldValues)
                        {
                            string CustomFieldName = item.IncludeCustomFields.CustomFields.ToList().Where(pr => pr.InternalName == cust.Key).ToList().Count == 0 ? string.Empty : item.IncludeCustomFields.CustomFields.ToList().Where(pr => pr.InternalName == cust.Key).ToList()[0].Name;

                            string CustomFieldID = cust.Key.ToString();
                            string CustomFieldValue = cust.Value.ToString();
                        }
                    }


                }
            }
        }

    }
}

 


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.

error: Content is protected !!