Check if user is member of a SharePoint group


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. public static class SecurityHelper
  2. {
  3. public static bool IsUserMemberOfGroup(SPUser user, string groupName)
  4. {
  5. bool result = false;
  6.  
  7. if (!String.IsNullOrEmpty(groupName) && user != null)
  8. {
  9. foreach (SPGroup group in user.Groups)
  10. {
  11. if (group.Name == groupName)
  12. {
  13. // found it
  14. result = true;
  15. break;
  16. }
  17. }
  18. }
  19.  
  20. return result;
  21. }
  22. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.