using
System;
System.Collections.Generic;
System.Linq;
System.Text;
Microsoft.SharePoint;
System.Collections;
Microsoft.Office.Server.UserProfiles;
Microsoft.Office.Server;
namespace
RahulCheckSitePermission
{
class
Program
static
void
Main(
string
[] args)
Console.WriteLine(
"This tool will check the permissions of a user in the site specified"
);
"Please enter the URL of the site where you want to check the permissions"
String webUrl = Console.ReadLine();
"Please enter the userName"
String userName = Console.ReadLine();
try
(SPSite site =
new
SPSite(webUrl))
(SPWeb web = site.OpenWeb())
ServerContext serverContext = ServerContext.GetContext(site);
UserProfileManager userProfileManager =
UserProfileManager(serverContext);
UserProfile userProfile = userProfileManager.GetUserProfile(userName);
String userLogin = userProfile[PropertyConstants.AccountName].Value.ToString();
SPUserCollection groupUsers;
ArrayList userInGroups =
ArrayList();
userInGroups.Add(userLogin);
SPPrincipal userPrincipal;
SPGroupCollection groups = web.Groups;
foreach
(SPGroup group
in
groups)
groupUsers = group.Users;
(SPUser groupUser
groupUsers)
if
(groupUser.Name.Equals(userLogin))
userInGroups.Add(group.Name);
break
;
}
SPRoleAssignmentCollection roleCollection = web.RoleAssignments;
(SPRoleAssignment role
roleCollection)
userPrincipal = role.Member;
for
(
int
i = 0; i < userInGroups.Count; i++)
(userInGroups[i].ToString().Equals(userPrincipal.Name))
SPRoleCollection roles = userPrincipal.Roles;
(SPRole userrole
roles)
"The user "
+ userLogin +
" has permissions of "
+ userrole.Name +
" given via "
+ userPrincipal.Name);
"The execution completed"
Console.ReadLine();
catch
(Exception e)
Console.WriteLine(e.Message);
Richard Mueller edited Revision 2. Comment: Removed (en-US) from title
Craig Lussier edited Revision 1. Comment: added en-US to tags and title