0

I am working on a remote event receiver, and i want to reference a mail-enabled security group using the email, i tried this:-

context.Load(context.Web.SiteUsers);
context.ExecuteQuery();
User pmoGroup = context.Web.SiteUsers.Where(a => a.Email.ToLower().StartsWith("pmo@")).SingleOrDefault();

now this security group is already added to a SharePoint group, so it should be inside the siteUsers (inside the user info hidden list), but my above code will get null value for the pmoGroup. any advice?

1

Instead of accessing the siteusers, can we iterate all the users from the "User Information List" as below and from that can we take the pmogroup,

ClientContext clientContext = new ClientContext("http://your site/");
Web web = clientContext.Web;
List siteUserInfoList = web.SiteUserInfoList;
CamlQuery query = new CamlQuery();
query.ViewXml = "";
IEnumerable<ListItem> itemColl = clientContext.LoadQuery(siteUserInfoList.GetItems(query));
clientContext.ExecuteQuery();
foreach (var item in itemColl)
{
    Console.WriteLine("ID:{0}  Email:{1} Title:{2}", item.Id, item["EMail"], item["Title"]);
   if(item["EMail"]!= null){
    if(item["EMail"].StartsWith("pmo@")){
       var userValue = (FieldUserValue)item["Name"];
       var user = clientContext.Web.GetUserById(userValue.LookupId);
       clientContext.Load(user, x => x.LoginName);
       clientContext.ExecuteQuery();
       string thisWillBeUsersLoginName = user.LoginName;
    }
   }
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.