public static string GetUserFieldType(ClientContext ctx, FieldUserValue value)
{
var objList = ctx.Site.RootWeb.SiteUserInfoList;
var userInfo = objList.GetItemById(value.LookupId);
ctx.Load(userInfo, i => i.ContentType);
ctx.ExecuteQuery();
return userInfo.ContentType.Name;
}
public void Getpersonorgroupvalue()
{
using (ClientContext clientContext = new ClientContext("SiteCollectionUrl"))
{
clientContext.Credentials = new NetworkCredential("UserName", "Password", "DomainName");
Web web = clientContext.Web;
clientContext.Load(web);
clientContext.ExecuteQuery();
var list = web.Lists.GetByTitle("ListName");
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = @"<View></View>";
Microsoft.SharePoint.Client.ListItemCollection lstCollection = list.GetItems(camlQuery);
clientContext.Load(lstCollection);
clientContext.ExecuteQuery();
FieldUserValue[] objfieldvalue = lstCollection[0]["PersonGroupColumnName"] as FieldUserValue[];
if (objfieldvalue != null && objfieldvalue.Length > 0)
{
for (int UserIndex = 0; UserIndex < objfieldvalue.Length; UserIndex++)
{
string type = GetUserFieldType(clientContext, objfieldvalue[UserIndex]);
break;
}
}
for (int UserIndex = 0; UserIndex < objfieldvalue.Length; UserIndex++)
{
string UserId =Convert.ToString(objfieldvalue[UserIndex].LookupValue);
break;
}
}
}