C# Programmatically simulate SharePoint Online "Specific People" for an external user and track their activity

Senthil Kumar S 1 Reputation point
2021-08-01T11:32:29.793+00:00

I have a requirement to programmatically simulate the "Specific people" functionality using CSOM or PnP. (Please refer to the screenshot for the Specific people option).

I tried the following programmatically however it generates only Anonymous Link which does not help in my situation as the user is always tracked as "Guest User".

My requirement is to send unique links to each external user identified by email id and when there is a change made to the document by the external user, I need to track them.

Code used by me is,

    public void ShareTheDocument(ClientContext context, List<string> emails, string absoluteDocUrl)  
    {  

            var userRoles = new List<UserRoleAssignment>();  
            foreach (var user in emails)  
            {  
                UserRoleAssignment role = new UserRoleAssignment();  
                role.UserId = user;  
                role.Role = Role.Edit;  
                userRoles.Add(role);  
            }  
             
            IList<UserSharingResult> userSharingResults =  DocumentSharingManager.UpdateDocumentSharingInfo(context, absoluteDocUrl, userRoles, false, true, true, "New Document - 1", true, false);  
            context.ExecuteQuery();  

    }  

119592-image.png

PLEASE HELP. Thank you.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,300 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,810 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 33,641 Reputation points Microsoft Vendor
    2021-08-02T02:44:35.643+00:00

    Hi @Senthil Kumar S ,
    Currently there is no such way to meet your requirement.
    I have tested that the file can only be shared with existing users,but can't be shared with external users not exist.


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.