Search This Blog

Wednesday, May 30, 2012

CurrentUserGroup-Sharepoint 2010

public static string GetCurrentUserGroup()

{

string GroupName = "";

using (SPSite site = new SPSite(SiteUrl))

{

site.AllowUnsafeUpdates = true;

using (SPWeb spweb = site.OpenWeb())

{

spweb.AllowUnsafeUpdates = true;

SPGroupCollection groupCollection = spweb.Groups;

foreach (SPGroup grp in spweb.CurrentUser.Groups)

{

foreach (SPGroup group in groupCollection)

{

if (grp.Name.Equals(group.Name))

{

GroupName = grp.Name; break;

}

//Get Role Assignments for Current User - If he has been directly assigned permissions

try { }

catch (Exception) {/*Best attempt to catch Exceptions*/}

}

}

spweb.AllowUnsafeUpdates = false;

} site.AllowUnsafeUpdates = false;

}

return GroupName;

}

No comments:

Post a Comment