Remove Share Option Manually And Programmatically

In this blog, we will see how to remove Share option from SharePoint site programmatically as well as manually.

Share

Share option can only  be  for the normal users, while Site Collection Administrators and owners will still be able to see this option.

To remove Share option manually

Go to Site Settings –> Site Permissions –> Access Request Settings (from ribbon)

Uncheck the check box for allowing access request and click OK.

check box

Shareoption

To remove Share option from the code:

Add the following references:

Microsoft.SharePoint.dll

Add the following namespaces:

Using Microsoft.SharePoint:

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using Microsoft.SharePoint;  
  6. namespace ConsoleAppRemoveShare  
  7. {  
  8.     class Program {  
  9.         static void Main(string[] args) {  
  10.             SPSite site = new SPSite(“http: //serverName:7777/”);  
  11.                 SPWeb web = site.RootWeb; web.RequestAccessEmail = “”; site.Dispose();  
  12.             }  
  13.         }  
  14.     }