Pages

Friday, May 17, 2013

Check User available in that Sharepoint Group or Not using SP Object Model


If the User available in that SP Group or Not via SP Object Model



private void GetSecurityGroup()

{

// Write your code here.

string SecurityGroupflag = "";

using (SPSite siteCollection = SPContext.Current.Site)

//using (SPSite siteCollection = new SPSite(properties.WebUrl))

{

using (SPWeb site = siteCollection.OpenWeb())

{

string groupName = "GWPSecurity";

//Get the current logged in user

SPUser currentUser = site.CurrentUser;

//Get all the user groups in the site/web

SPGroupCollection userGroups = currentUser.Groups;

//Loops through the groups and check if the user is part of given group or not.

foreach (SPGroup group in userGroups)

{

//Checking the group

if (group.Name.Contains(groupName))

{

SecurityGroupflag = "true";

break;

}

else

{

SecurityGroupflag = "false";

}

}

}

}

XPathNavigator datasource;

datasource = this.MainDataSource.CreateNavigator();

datasource.SelectSingleNode("/my:myFields/my:GWP_Security_Check_Group", NamespaceManager).SetValue(SecurityGroupflag);

}

No comments:

Post a Comment