SharePoint Online: how to block members to reshare files, folders or site via UI and CSOM

Hello,

I would like to show you a new feature available in SharePoint Online and in OneDrive for Business, that allow you to block your collaborators to share again your file with other, if they are not the owner.

Imagine the case that you’re sharing a file in your OneDrive for Business with somebody working at Microsoft or somebody working inside your organization for example. But you don’t want to allow him to share this file again with his colleagues.

You have a feature via the UI or via CSOM, that allow you to block this and then only allow the owner of the site to share.

To access it:

  1. Go to site settings
  2. Click on “Site permissions”
  3. Click “Access request settings”
  4. You will see this pop-up coming:blog 1
  5. Simply disable the box “Allow members to share the site and individual files and folders.”

Then you’re all set. But you can also programmatically change this property with the CSOM.

You must use the 16th version of the SharePoint Client library.


using (ClientContext ctx = new ClientContext("[mySharePointorOneDriveSite]"))
{
// secure the password
SecureString password = new SecureString();
Array.ForEach("[pwdLogin]".ToCharArray(), c => password.AppendChar(c));

// create the credentials object to conncet to SP Online
var credentials = new Microsoft.SharePoint.Client.SharePointOnlineCredentials("[userLogin]", password);
ctx.Credentials = credentials;

//disable the property, to block members to reshare
ctx.Web.MembersCanShare = false;
ctx.Web.Update();
ctx.ExecuteQuery();
}
Advertisements
This entry was posted in OneDrive, SharePoint. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s