0

We want to programatically enable external user access to a list item in a SharePoint Online List/ Library. This should allow us to pass an individual user email address and allow external access to that user account.

As per my understanding, it doesn't expose any API to enable external user access using a programmatic method and appreciate any support.

1 Answer 1

0

You can generate an anonymous link using the CreateAnonymousLinkForDocument PnP CSOM extension method as below and then share the document with external user:

string link = context.Web.CreateAnonymousLinkForDocument("https://tenantname.sharepoint.com/Documents/sample.docx",ExternalSharingDocumentOption.View);

Or you can also use the UpdateDocumentSharingInfo method to share documents with external users as below:

var userRoles = new List<UserRoleAssignment>();
var users = new List<string>() { "[email protected]", "[email protected]" };
foreach (var user in users)
{
    UserRoleAssignment role = new UserRoleAssignment();
    role.UserId = user;
    role.Role = Role.Edit;
    userRoles.Add(role);
}
string message = "Please accept this invite to access the document.";

string fileUrl = "https://tenantname.sharepoint.com/sites/test/Documents/Document.docx";
DocumentSharingManager.UpdateDocumentSharingInfo(context, fileUrl, userRoles, true, true, true, message, true, true);
context.ExecuteQuery();

References -

External sharing API for SharePoint and OneDrive for Business

Invite external users to SharePoint site using CSOM

PnP Github Sample - Core.ExternalSharing

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.