Tuesday, April 30, 2013
Get All Users from Web Application programatically
static void Main(string[] args)
{
String ConfigValues = ConfigurationSettings.AppSettings["WebAppsName"];
String[] ObjWebapps = ConfigValues.Split('|');
foreach (String WebappsName in ObjWebapps)
{
SPWebApplication webApp = SPWebApplication.Lookup(new Uri(WebappsName));
int count = webApp.Sites.Count;
foreach (SPSite ObjSites in webApp.Sites)
{
AllUsers(ObjSites.Url);
}
}
// AllUsers();
}
protected static void AllUsers(String SiteName)
{
using (SPSite site = new SPSite(SiteName))
{
using (SPWeb web = site.OpenWeb())
{
foreach (SPRoleAssignment roleAssignment in web.RoleAssignments)
{
if (roleAssignment.Member is SPGroup)
{
foreach (SPRoleDefinition roleDefinition in roleAssignment.RoleDefinitionBindings)
{
// ("\t" + roleDefinition.Name);
if (roleDefinition.Name.Equals("Contribute"))
{
var group = (SPGroup)roleAssignment.Member;
foreach (SPUser user in group.Users)
{
//("Contribute Permission Level" + "----" + "User Name" + user.Name);
}
}
if (roleDefinition.Name.Equals("Full Control"))
{
var group = (SPGroup)roleAssignment.Member;
foreach (SPUser user in group.Users)
{
//("Contribute Permission Level" + "----" + "User Name" + user.Name);
}
}
if (roleDefinition.Name.Equals("Read"))
{
var group = (SPGroup)roleAssignment.Member;
foreach (SPUser user in group.Users)
{
//("Read Permission Level" + "----" + "User Name" + user.Name);
}
}
if (roleDefinition.Name.Equals("View Only"))
{
var group = (SPGroup)roleAssignment.Member;
foreach (SPUser user in group.Users)
{
//("View Only Permission Level" + "----" + "User Name" + user.Name);
}
}
}
}
}
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment