Let us explore how to use the SharePoint CSOM code to do the same operations for larger data sets.SharePoint-2013-Hosting

Generate a Report of all the Sharing Links created

This is a sample console app code which assumes you have installed the ‘Microsoft.SharePointOnline.CSOM’ nugget package (I am using version – 16.1.9021.1200).This snippet reads all the items within a document library and checks if the document has unique permissions or not. If a document has unique permissions we then use the Web.GetObjectSharingSettings method to fetch the sharing details of a document
The ObjectSharingInformation class of the SharePoint CSOM have some useful properties which can be used to find the sharing details. Two important properties which can be used for generating reports are the ‘ObjectSharingInformation. SharedWithUsersCollection’, which shows the list of users for whom the sharing links are accessible and ‘ObjectSharingInformation.SharingLinks’, which gives the sharing link URLs for a given document.
This snippet shows the list of documents which have Sharing Links created and the list of sharing links for it. This snippet can be extended to generate reports on which all users created the sharing links, who all are invited to view or edit a document etc.

Delete all the Sharing Links within a library

As mentioned in the previous post, the recommended way to remove all sharing links on a document library is to delete the unique permissions on the document. Doing this not only removes the unique permissions but also deletes all the sharing links on the document. The below snippet can be used to find all documents with unique permissions and reset the permissions, and in turn remove all the sharing links.
Hope this series of posts about Sharing Links is useful to understand about the relation between Sharing Links and Unique Permissions and plan on how to use the CSOM code to effectively generate reports and remove all the sharing links within a document library when needed.