Tuesday, September 23, 2008

Checking if a user has View Rights in Site Collection

SPSite siteCollection = new SPSite("http://localhost"); 

SPWeb ParentWeb = siteCollection.OpenWeb("/");
SPUserCollection allUsers = ParentWeb.Users;

foreach ( SPUser user in allUsers) {

if (user.LoginName.ToLower() == "sandeep") {

SPRoleCollection allGroups = user.Roles;

foreach ( SPRole role in allRoles) {

int right = group.PermissionMask & SPRights.ViewListItems;

if (right == SPRights.ViewListItems) {

Console.Write("User has Reader permissions.");

}
}
}
}

0 comments: