Retrieve Person or Group field using SharePoint 2013 Client Object Model

I’m involved in troubleshooting a crazy people picker field issue in SharePoint 2013, which necessitates me to programmatically query the Person or Group field of SharePoint list using Client Object model. I was trying to figure out the exact syntax that can be used to grab the Person or Group field using FieldUserValue objects. Here is the complete code below :-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Client;
using System.Net;

namespace ReadApproverNameField
{
    public class Program
    {
        static void Main(string[] args)
        {
            GetApproverDetails();
            Console.ReadLine();

        }

        public static void GetApproverDetails()
        {
            ClientContext clientContext = new ClientContext(http://servername/sites/sitecollectionname);
            
            NetworkCredential oNetworkCredential = new NetworkCredential();
            oNetworkCredential.Domain = @"Domain Name";
            oNetworkCredential.UserName = @"User Id";
            oNetworkCredential.Password = @"Password";
            clientContext.Credentials = oNetworkCredential;

            List list = clientContext.Web.Lists.GetByTitle("Name of the list");

            CamlQuery camlQuery = new CamlQuery();
            camlQuery.ViewXml = "<View/>";
            ListItemCollection listItems = list.GetItems(camlQuery);
            clientContext.Load(list); 
            clientContext.Load(listItems);
            clientContext.ExecuteQuery();


            foreach (ListItem oListItem in listItems)
            {
                
                FieldUserValue name = oListItem.FieldValues["ApproverName"] as FieldUserValue;
                string person = name.LookupValue;                
                Console.WriteLine(oListItem.Id + "     " + oListItem["Title"].ToString() + "     " + person);


            }
        }
    }
}
Basically we cannot create a new instance of FieldUserValue object, it needs to be casted from the current item’s field using ‘as FieldValue’ syntax
and then the LookupValue need to be invoked to fetch the value. If we run the above code, we’ll get the output below.
pic1

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

 Subscribe to my blog

Import MS Project 2010 plan to Project Server

This article will cover the steps required to import the Project Plan created in MS Project 2010 to the Project Server (Project Web Access). This assumes that you’ve already established a connectivity to the Project Server through File –> Info –> Manage Accounts –> Add

pic1

Now let’s add an option in the Ribbon Control to enable upload the project plan to Project Server

File –> Options –> Customize Ribon

Under Main Tabs –> Project –> Create a a new group pressing ‘New Group’ button

On the left side –> Choose commands from –> Select ‘Import Project to Enterprise’

pic2

Now you’ll get to see an option called ‘Import Project to Enterprise’ under Projects in Ribbon.

 Subscribe to my blog

Connecting MS Project 2010 to Project Web App

I was trying to connect MS Project 2010 to a Project Web App (MS Project Server), got this error “.

pic1

The root cause of the issue was that, the MS Project 2010 was not able to connect to Project Web App using the logged on user’s credential.

I had to make a change to the following browser settings to get this working.

IE –> Tools –> Internet Options –> Security –> Intranet (in my case PWA site is hosted in intranet zone)

Custom Level –> User Authentication –> Logon –> Prompt for user name and password

pic2

 Subscribe to my blog

You can’t remotely debug events Windows Azure Service Bus connection string is missing

I was trying to debug a SharePoint 2013 remote event receiver running against a SharePoint Hosted App in Visual Studio 2012. I got the following error.

pic1

I learnt that I need to create a Windows Azure Service Bus and configure the end point of Azure Service Bus in the Visual Studio project property.

Create a new service bus object in Azure Management Portal

pic3

Go to project property in Visual Studio 2012 –> SharePoint Tab –> Enable Remote Debugging by providing the endpoint of the Azure Service Bus

pic4

Now we’re able to debug the remote event receiver in Visual Studio 2012.

pic2

 Subscribe to my blog

Microsoft MVP Lunch Hour Session on Sep 18

I’m conducting a session for the South Asia Microsoft MVP Lunch Hour series  on Microsoft events online platform (msevents.microsoft.com).

The topic is ‘SharePoint 2013 Remote Event Receivers” and it will be a Level 300 session. The event date is 18’th September 2013.

If you are interested, please register it in the below link
https://msevents.microsoft.com/CUI/EventDetail.aspx?EventID=1032561518&Culture=en-IN&community=0

 Subscribe to my blog