Pages

Friday, May 17, 2013

Get Sharepoint Group User's Name and User Email id via SP Object Model


Get SP Group User's Name and User Email id via SP Object Model:

 

private void GetSecurity()

{

string GetSecurity = string.Empty;

string GetSecurityEmail = string.Empty;

using (SPSite site = new SPSite(SPContext.Current.Web.Url))

{

using (SPWeb web = site.OpenWeb())

{

SPGroup gp = web.Groups["GWPSecurity"];

if (gp != null)

{

foreach (SPUser usr in gp.Users)

{

//if (usr.Name != "System Account")

//{

if (GetSecurity == "")

GetSecurity += usr.Name;

//else

// GetSecurity += ", " + usr.Name;

if (GetSecurityEmail == "")

GetSecurityEmail += usr.Email;

else

GetSecurityEmail += ";" + usr.Email;

//}

}

}

}

}

XPathNavigator datasource;

datasource = this.MainDataSource.CreateNavigator();

datasource.SelectSingleNode("/my:myFields/my:NewSecurityName", NamespaceManager).SetValue(GetSecurity);

datasource.SelectSingleNode("/my:myFields/my:SecurityofficerEmail", NamespaceManager).SetValue(GetSecurityEmail);

}

 

No comments:

Post a Comment