What is the proper approach to implement file sharing in Sharepoint?

Мария Михальская 6 Reputation points
2022-12-15T12:21:12.91+00:00

Hello! I experience a problem trying to implement file sharing logic using Graph API. I tried several ways to do it: direct invitation and sharing link. Nothing seems working for me.

If we use invite for sharepoint file it is shared. But can't be unshared.

Permission of sharing link can contain several users. And if I remove permission to unshare file for one user, it is unshared for other user as well.
And there is no way to create separate sharing links (with same configs) (and so different permission IDs) for each user. As far as I know.

Would appreciate a lot if anyone let me know if there is any way to unshare file for specific user at all if I'm the person, who is able to share file? I see no info how to do it in documentation
I will be glad if it is possible even if not using sharing link. Any working approach to share and unshare file for specific user will do.

Microsoft 365 and Office | SharePoint | Development
Microsoft Security | Microsoft Graph
{count} votes

1 answer

Sort by: Most helpful
  1. Tong Zhang_MSFT 9,251 Reputation points
    2022-12-16T08:20:20.037+00:00

    Hi @Мария Михальская ,

    As far as I know, currently, there are no other Graph APIs that implement file sharing other than direct invitations and sharing links. As a workaround, I recommend you use the following methods to remove a specific user access to a SharePoint list item via REST API:

    1.You have to break the inheritance from the parent which can be done using the below endpoint:

    _api/web/lists/getByTitle(<List Title>)/items/getById(<Item id>)/breakroleinheritance(copyRoleAssignments=false,clearSubscopes=true)  
    

    2.Find the permission level ID.

    _api/web/roledefinitions/getByName('contribute')  
    

    3.Get the user id.

    4.Remove user permissions from the list item

    <siteUrl>/_api/web/lists/getbytitle('<listName>')/items(<ID>)/roleassignments/removeroleassignment(principalid=<userID>,roleDefId=1073741827)  
    

    Similar issues for reference:
    Remove Specific User Access to a SharePoint List Item
    How to remove specific user from item level permission through Rest API

    Hope it can help you. Thanks for your understanding.

    Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    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.



Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.