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

Aaeeschylus 21 Reputation points
2021-08-26T01:47:53.717+00:00

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 https://github.com/pnp/pnpframework. 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,
           email,
           ExternalSharingDocumentOption.View,
           false,
           "");

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:
55YWd.png

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

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.

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

Accepted answer
  1. MichaelHan-MSFT 18,046 Reputation points
    2021-08-26T07:14:20.107+00:00

    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

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.