SharePoint Pals
 | Sign In
How to Enable Auto Approval For Permission Requests in Community Site Template – SharePoint Office 2013 Programmatically using Client Side Object Model (CSOM) C#
by Sathish Nadarajan 18 Nov 2016
Author
SharePoint MVP
Visits   
Today  :   24     Total  :    1062

Recently, I was working with the Community Site Template, which has very interesting Social Collaboration features. For an Organization, there will be so many community sites, created by some individuals like project managers, program managers. The team members wish to join the community. By default, everyone will be Visitor for the communities within an organization. i.e., everyone can login to the community site within the organization. But they may not be post any comments or contribute to the community site until they become the member.

To become a member, on the community site itself, there is an option called “Join Community”.

clip_image002

By Clicking this Join Community, an email will be triggering to the community admin and on the approval, of the admin, the member will be added to the Members Group.

But, every time, the admin may not want to approve the joining requests. Like in migration projects, the sites will be auto generated. In that case, we need to enable the auto approval also.

There is an option in the UI itself to do this. First let us see that and then we will go to the CSOM code to do the same functionality.

1. Go to Members Page. (as shown in the above image)

2. Click on Community Settings.

clip_image004

3. Select the Option “Enable auto-approval”

clip_image006

4. Click OK.

This will enable the auto approval of the members to join the community. Now, if any team members, click on the Join Community, they will be added to the community without any approval.

I met with a requirement to do this process through Code. As I told you, in case of auto creating the community sites at that time, we need to have a exe or scheduled jobs or any kind of triggering mechanism to change this settings.

After some analysis, I found that the value is being stored in a property bag. A very straight forward approach.

Updating the Property Bag Value of the Key “vti_CommunityEnableAutoApproval” Will do the magic for us.

The code is as follows.

 namespace Console.Office365
 {
     using Microsoft.SharePoint.Client;
     using Newtonsoft.Json.Linq;
     using System;
     using System.Collections.Generic;
     using System.IO;
     using System.Linq;
 
     class Program
     {
         static void Main(string[] args)
         {
             EnableAutoApprovalForPermissions();
         }
 
 
         public static void EnableAutoApprovalForPermissions()
         {
             OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();
 
             string siteUrl = "https://*****.sharepoint.com/sites/communitysite";
             string userName = "Sathish@****.onmicrosoft.com";
             string password = "********";
 
             using (var ctx = authMgr.GetSharePointOnlineAuthenticatedContextTenant(siteUrl, userName, password))
             {
                 Web web = ctx.Web;
                 PropertyValues properties = ctx.Web.AllProperties;
                 ctx.Load(web);
                 ctx.Load(properties);
                 ctx.ExecuteQueryRetry();
 
                 properties["vti_CommunityEnableAutoApproval"] = "True";
 
                 web.Update();
                 ctx.Load(web.AllProperties);
                 ctx.ExecuteQueryRetry();
 
             }
         }
 
 
 
 
 
     }
 
 }
 

Hope this helps.

Happy Coding,

Sathish Nadarajan.

blog comments powered by Disqus

SharePoint Pals

Pals
SharePoint Pals, a community portal for SharePoint developers, Administrators and End Users. Let's join hands and share the point together.
Read this on mobile

Training

Angular Js Training In Chennai
Advanced Angular Js training with real world developer scenarios
Angular Js, Web Api and Ionic for .Net Developers
All in one client side application development for .Net developers
Angular Js For SharePoint Developers
Get ready for the future. Its no more just C#

Get Connected

SharePoint Resources

SharePoint 2013 and 2010 Web Parts
Free Web Parts with Source Code for SharePoint Community




SharePoint 2013 Books and Tutorials
Collection of free SharePoint 2013 books and tutorials (eBooks, pdfs)

Supported By

Contribute your article and be eligible for a one month Free Subscription for Plural Sight. The Author of the most popular New Article (published in the previous month) will be awarded with a Free One month Plural Sight Subscription. Article can be sent to articles@sharepointpals.com in a word document.

Related Resources

Recent Tweets

Twitter November 21, 21:08
Implementing Multi-Threading with MaxDegreeOfParallelism in SharePoint using CSOM – An Insight - https://t.co/RNM7eVuyaa

Twitter November 21, 12:48
Configure Windows Firewall for SQL Server Analysis Service (SSAS) - https://t.co/re2H0cnGwn

Twitter November 21, 12:46
Implementing Multi-Threading in SharePoint To Upload Files using CSOM C# – An Insight - https://t.co/18QwUQG2eR

Twitter November 20, 21:48
How to Get the Client Context Using App Access token, by passing Client ID using CSOM in SharePoint Office 365 - https://t.co/wpmlJfTeWx

Twitter November 18, 21:30
How to Enable Auto Approval For Permission Requests in Community Site Template – Office 2013 using Client Side Object Model (CSOM) C#

Follow us @SharePointPals
Note: For Customization and Configuration, CheckOutRecent Tweets Documentation