0

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:

enter image description here

Lastly, is there are way to isolate Anonymous Share URL link(s) to a specific site and not entire tenant?

2 Answers 2

1

You need to set as following pic since you haven't set access for anonymous enter image description here

1
  • Thanks @RaytheonXie-MSFT this is very helpful and thanks for including the screenshot!
    – seanrco
    Sep 15, 2021 at 7:56
1

You need to set "Sharing outside your organization" to "Allow sharing to authenticated external users and using anonymous access links" "Default link type" to "Anoymous Access - anyone with the link"

1
  • Thanks @user100109 this is helpful!
    – seanrco
    Sep 15, 2021 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.