mardi 17 mars 2015

Sharepoint 2010 CSOM Get user and his groups by login name



I want to get a user and all his groups by a login name. Easy to do in Sharepoint 2013.



clientContext.Load(site, l => l.RootWeb.SiteUsers, l => l.RootWeb.Id, l => l.Id);
clientContext.ExecuteQuery();

var user = site.RootWeb.SiteUsers.GetByLoginName(loginName);
clientContext.Load(user, l => l.Groups, l => l.Id, l => l.LoginName);
clientContext.ExecuteQuery();


As both the SiteUsers as well as the Groups Property don't exist in SP2010 i have no idea how to accomplish this. Any ideas who i can get the needed information?


The only information i can use is the login name, CurrentUser or something similar won't work.


EDIT: I have found a way to get the User object via CurrentUser, nevertheless i can't find a reliable way to get the groups for this user. I can iterate through all groups of the site and check if they contain the user. But then i have to also resolve all AD Groups and consider special AD Groups like "NT AUTHORITY\authenticated users". Makes the whole process rater slow. Is there a faster way to do this in SP2010?








0 commentaires:

Enregistrer un commentaire