Prevent Guest Access when sharing a document or folder on Sharepoint using CSOM

Aaeeschylus 21 Reputation points

I am developing a tool for my company that allows people to share files from our network with clients in a very automated way to make sharing documents easier for everyone. However, I have run into a bit of a problem when it comes to sharing the documents themselves.

Currently, when someone shares a document, it uses the "ShareDocument" extension from My implementation of it is as follows (email is just a variable containing the provided email address of the client):

result = context.Web.ShareDocument(site,

This works perfectly and overall, my software is done and in a working state. However, there is one thing that really bothers me and will definitely cause confusion. When sharing with some clients who are considered guests, they don't get the normal external sharing link. Instead, they get given direct access. The issue with this is that for me to provide the links to the user to share, I need to provide two (external share link and direct access link) and specify which client works for each link. For example:

I want all emails to be shared like this:

But some users who Sharepoint considers guests are being shared like this:

Does anyone know how I can force Sharepoint to share users through the "Links Giving Access" method instead of with the "Direct Access" method. It can be done manually but that makes the development of this tool to be pointless. I am happy to modify the PnPFramework extensions if necessary, I am just unsure where to even start.

I have tried making a custom people picker input which copies the people picker input for an email that does get given the correct link and just replaced the email in it with the "guest" user's email but that made no difference.

A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,793 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,701 questions
0 comments No comments
{count} votes

Accepted answer
  1. MichaelHan-MSFT 18,016 Reputation points

    Hi @Aaeeschylus ,

    As far as I know, currently there is no such method to share users through the "Links Giving Access" way using CSOM.

    For the sharing link, we can only create anonymous link uisng CreateAnonymousLinkForDocument method currently.

    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.

0 additional answers

Sort by: Most helpful