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
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.
-
Is this still the case 2 years on? I need to do this and still can't find a way that will allow inviting external users programmatically..?– JaymzOct 10, 2016 at 12:45
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();
}
Not by CSOM but you can invite a Guest user by using PowerShell along with Azure Function or Azure logic app service.