How to get user belongs to which group in sharepoint?
I have 350 groups in in my sites collection. I need to find a user by passing login name ge开发者_Python百科t his groups belongs to? How to get programmatically?
- Use SPWeb.AllUsers collection to get the
SPUser
by login name (alternatively use SPWeb.EnsureUser if you don't know if they have been added yet) - Use SPUser.Groups to get the groups the user is a member of
Checkout this excellent post on ASP.NET forums:
C# Example: How to get all groups, users and roles from SharePoint using SPGroup, SPUser, SPRole ...
CheckOut this one
SPFieldUserValue usersField = new SPFieldUserValue(SPContext.Current.Web); bool isUser = SPUtility.IsLoginValid(SPContext.Current.Site, usersField.User.LoginName); SPGroup group = SPContext.Current.Web.Groups.GetByID(usersField.LookupId);
精彩评论