Create Group In SharePoint 2013 Online Using CSOM

Introduction

In this article, we will see how to create a user group in SharePoint 2013 Online UI and programmatically, using CSOM. We will learn how to perform basic group operations with SharePoint Online O365. 

A SharePoint group is a collection of users, who all have the same set of permissions or permission levels. SharePoint Online groups can simplify the list/library permission assigning and managing site access. We can organize the users into any number of groups or we can restrict the permission number of groups, which depends on the size and complexity of your organization or a Website.

Administrators can create a security group to grant a certain group of people access to a SharePoint 2013 Online site. Office365 Tenant administrators have permissions to create, edit or delete security groups for more information about administrator roles.

To create a new security group, select the new link.

You’ll then be asked to provide a name and description for the security group.

If you want to access SharePoint2013 permission group site directly, access the URL given below.

https://gowthamr.sharepoint.com/sites/TestSite/_layouts/15/user.aspx

Follow the steps given below to create a new group in SharePoint Online.

Click O365 settings icon.

SharePoint

The drop down menu, which you can see in the Site permissions link, the link needs to be selected.

SharePoint

Select site Permission link,

SharePoint
Click advanced permission settings link.

SharePoint
Click Create Group in SharePoint Online, type a name and description for the group.

Enter the owner name details here because, the owner can change anything about the group such as adding and removing the members or deleting the group. Only one user or a group can be the owner.
SharePoint

Specify who has permission to see the list of group members and who has permission to add and remove the members from the group.

SharePoint

Specify whether to allow the users to request membership in this group and allow the users to request to leave the group. All the requests will be sent to the specified E-mail address. If auto-accept is enabled, the users will automatically be added or removed when they make a request. 

SharePoint

Choose the permission level group members to get on this site.

  • Full Control - Has full control.
  • Design - Can view, add, update, delete, approve and customize.
  • Edit - Can add, edit and delete lists; can view, add, update, delete list items and the documents.
  • Contribute - Can view, add, update and delete list items and the documents.
  • Read - Can view pages and list items and download the documents.

Save the group name, followed by new group, which is created successfully.

SharePoint

Now, we will see about create group in Office365, SharePoint 2013 Online programmatically, using CSOM.

Microsoft introduced a new functionality to interact with CSOM. With any interactions with the release, you can call in a class called "SharePointOnlineCredentials" and this will handle any authentication, which you should need to do.

This class is included in version 15 of Microsoft.SharePoint.Client dll

Connect SharePoint Online Site, using CSOM

Create a new class to store your credentials. 

  1. private class Configuration  
  2.         {  
  3.   public static string ServiceSiteUrl = "https:// https://gowthamr.sharepoint.com";  
  4.   public static string ServiceUserName = "[email protected]";  
  5.   public static string ServicePassword = "xxxxxxxxxx";  
  6.         }   

Add another class to create connected context with SharePoint Online credentials. 

  1. static ClientContext GetonlineContext()  
  2.         {  
  3.             var securePassword = new SecureString();  
  4.             foreach (char c in Configuration.ServicePassword)  
  5.             {  
  6.                 securePassword.AppendChar(c);  
  7.             }  
  8.   
  9.             var onlineCredentials = new SharePointOnlineCredentials(Configuration.ServiceUserName, securePassword);  
  10.   
  11.             var context = new ClientContext(Configuration.ServiceSiteUrl);  
  12.             context.Credentials = onlineCredentials;  
  13.   
  14.             return context;  
  15.         }   

Final code

Open Visual Studio 2012.

Create New Console Application, add a reference to assemblies

  1. ‘Microsoft.SharePoint.Client’   
  2.  ‘Microsoft.SharePoint.Client.Runtime’.  
  3. using System;  
  4. using System.Collections.Generic;  
  5. using System.Linq;  
  6. using System.Text;  
  7. using Microsoft.SharePoint.Client;  
  8.    
  9. namespace O365SPGroup  
  10. {  
  11.     class Program  
  12.     {  
  13.       
  14.       
  15.      private class Configuration  
  16.         {  
  17.                 public static string ServiceSiteUrl = "https:// https://gowthamr.sharepoint.com";  
  18.                 public static string ServiceUserName = "[email protected]";  
  19.                 public static string ServicePassword = "xxxxxxxxxx";  
  20.         }  
  21.   
  22.           static ClientContext GetonlineContext()  
  23.                {  
  24.         var securePassword = new SecureString();  
  25.         foreach (char c in Configuration.ServicePassword)  
  26.         {  
  27.         securePassword.AppendChar(c);  
  28.         }  
  29.     var onlineCredentials = new SharePointOnlineCredentials(Configuration.ServiceUserName, securePassword);  
  30.     var context = new ClientContext(Configuration.ServiceSiteUrl);  
  31.     context.Credentials = onlineCredentials;  
  32.     return context;  
  33.                    }  
  34.   
  35.         static void Main(string[] args)  
  36.         {  
  37.             var ClientContext=GetonlineContext();  
  38.             Web web = clientContext.Web;             
  39.             GroupCreationInformation groupCreationInfo = new GroupCreationInformation();  
  40.             groupCreationInfo.Title = "Gowtham_Group";  
  41.             groupCreationInfo.Description="Custom Group Created...";  
  42.             User owner = web.EnsureUser(@"XXXXXX");  
  43.             User member = web.EnsureUser(@"YYYYYY");   
  44.             Group group = web.SiteGroups.Add(groupCreationInfo);  
  45.             group.Owner = owner;  
  46.             group.Users.AddUser(member);  
  47.             group.Update();     
  48.             clientContext.ExecuteQuery();             
  49.         }  
  50.     }  
  51. }   

In this article, we have seen how to create group in office 365 UI. SharePoint Online Groups in Office 365 lets you choose a set of people, which you wish to collaborate with and easily set up a collection of resources for those people to share based on the permission levels.

Was my article helpful?

If so, please let us know at the bottom of this page. If not, let us know what was confusing or missing and I’ll use your feedback to double-check the facts, add info and update this article.