TransWikia.com

Create external users using CSOM

SharePoint Asked by Marlou on November 8, 2021

Does anyone know if it’s possible to invite external users with the client object model or is this only possible in the UI?

3 Answers

Not by CSOM but you can invite a Guest user by using PowerShell along with Azure Function or Azure logic app service.

https://docs.microsoft.com/en-us/azure/active-directory/external-identities/b2b-quickstart-invite-powershell

Answered by cjs on November 8, 2021

Please see an example below:

private void ShareTheWeb(ClientContext context, List<string> emails)
{
     var users = emails.Select(email => 
         new UserRoleAssignment
         {
             UserId = email,
             Role = Role.View
         });

     WebSharingManager.UpdateWebSharingInformation(context, context.Web, users.ToList(), true, null, true, true);
     context.ExecuteQuery();
}

private void ShareTheDocument(ClientContext context, List<string> emails, string absoluteDocUrl)
{
     var users = emails.Select(email =>
         new UserRoleAssignment
         {
             UserId = email,
             Role = Role.View
         });

     DocumentSharingManager.UpdateDocumentSharingInfo(context, absoluteDocUrl, users.ToList(), true, true, true, null, true, true);
     context.ExecuteQuery();
}

Answered by Roman on November 8, 2021

Right now there is no way to add external user programmatically or using CSOM.The reasom behind it seems that SPO Webservice wont provide a mechanism to do this.

Answered by Aanchal on November 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP