I am trying to generate Anonymous Share URL link(s) for documents using the following CSOM method:
internal static string GetFileShareUrl(ClientContext spClientContext, string fileRef){
string fileShareUrl = string.Empty;
if (spClientContext != null && !string.IsNullOrWhiteSpace(fileRef))
{
try
{
string fileUrl = GetFileUrl(fileRef); // method to get proper file url format for sharing
fileShareUrl = spClientContext.Web.CreateAnonymousLinkForDocument(fileUrl, ExternalSharingDocumentOption.View);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
return fileShareUrl;
}
Where ClientContext is obtained using App Only authenitication:
AuthenticationManager().GetACSAppOnlyContext
And is currently throwing the following exception:
Exception thrown: 'Microsoft.SharePoint.Client.ServerException' in mscorlib.dll
Sharing by link is not enabled on the web, site, or tenant.
Spoke with the SharePoint admin and they indicated they enabled sharing for “Only people in your organization”. Is that enough?
If not is based on the following options which would need to be enabled:
Lastly, is there are way to isolate Anonymous Share URL link(s) to a specific site and not entire tenant?