forked from pnp/PnP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
101 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# Manage users and groups # | ||
|
||
### Summary ### | ||
This scenario shows how you can manage groups and users inside a site collection. | ||
|
||
### Applies to ### | ||
- Office 365 Multi Tenant (MT) | ||
- Office 365 Dedicated (D) | ||
- SharePoint 2013 on-premises | ||
|
||
### Prerequisites ### | ||
None | ||
|
||
### Solution ### | ||
Solution | Author(s) | ||
---------|---------- | ||
Core.GroupManagement | Bert Jansen (**Microsoft**) | ||
|
||
### Version history ### | ||
Version | Date | Comments | ||
---------| -----| -------- | ||
1.0 | July 11th 2014 | Initial release | ||
|
||
### Disclaimer ### | ||
**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.** | ||
|
||
|
||
---------- | ||
|
||
# General comments # | ||
This shows how you can work with groups and users by adding/removing them to the site collection. Adding users and groups in one thing, next thing is giving them a permission level so that they’ve access to SharePoint and that’s also shown in this sample. The actual implementation of these group/user/permission level actions is implemented in OfficeDevPnP Core as extension methods. This results in a very easy to use model which is shown via below code snippets. | ||
|
||
## ADDING GROUPS AND ADDING USERS TO GROUPS ## | ||
```C# | ||
cc.Load(cc.Web, web => web.CurrentUser); | ||
cc.ExecuteQuery(); | ||
Microsoft.SharePoint.Client.User currentUser = cc.Web.CurrentUser; | ||
|
||
if (!cc.Web.GroupExists("Test")) | ||
{ | ||
Group group = cc.Web.AddGroup("Test", "Test group", true); | ||
cc.Web.AddUserToGroup("Test", currentUser.LoginName); | ||
} | ||
``` | ||
|
||
## REMOVING GROUPS ## | ||
```C# | ||
if (cc.Web.GroupExists("Test")) | ||
{ | ||
cc.Web.RemoveGroup("Test"); | ||
} | ||
``` | ||
|
||
## REMOVING USERS FROM GROUPS ## | ||
```C# | ||
cc.Load(cc.Web, web => web.CurrentUser); | ||
cc.ExecuteQuery(); | ||
Microsoft.SharePoint.Client.User currentUser = cc.Web.CurrentUser; | ||
if (cc.Web.GroupExists("Test")) | ||
{ | ||
if (cc.Web.IsUserInGroup("Test", currentUser.LoginName)) | ||
{ | ||
cc.Web.RemoveUserFromGroup("Test", currentUser.LoginName); | ||
} | ||
} | ||
``` | ||
|
||
## ADD PERMISSION LEVEL TO GROUP ## | ||
```C# | ||
if (cc.Web.GroupExists("Test")) | ||
{ | ||
cc.Web.AddPermissionLevelToGroup("Test", RoleType.Contributor); | ||
} | ||
``` | ||
|
||
## ADD PERMISSION LEVEL TO USER ## | ||
```C# | ||
cc.Load(cc.Web, web => web.CurrentUser); | ||
cc.ExecuteQuery(); | ||
Microsoft.SharePoint.Client.User currentUser = cc.Web.CurrentUser; | ||
cc.Web.AddPermissionLevelToUser(currentUser.LoginName, RoleType.Reader); | ||
``` | ||
|
||
## REMOVE PERMISSION LEVEL FROM GROUP ## | ||
```C# | ||
if (cc.Web.GroupExists("Test")) | ||
{ | ||
cc.Web.RemovePermissionLevelFromGroup("Test", RoleType.Reader); | ||
} | ||
``` | ||
|
||
## REMOVE PERMISSION LEVEL FROM USER ## | ||
```C# | ||
cc.Load(cc.Web, web => web.CurrentUser); | ||
cc.ExecuteQuery(); | ||
Microsoft.SharePoint.Client.User currentUser = cc.Web.CurrentUser; | ||
cc.Web.RemovePermissionLevelFromUser(currentUser.LoginName, RoleType.Reader); | ||
``` | ||
|
This file was deleted.
Oops, something went wrong.