question

Aaeeschylus-2679 avatar image
0 Votes"
Aaeeschylus-2679 asked Aaeeschylus-2679 commented

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

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.

office-sharepoint-onlinesharepoint-dev
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MichaelHan-MSFT avatar image
0 Votes"
MichaelHan-MSFT answered Aaeeschylus-2679 commented

Hi @Aaeeschylus-2679,

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.

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hmm, but if Sharepoint doesn't consider them a "Guest User", it does already by default share it via the "Links Giving Access" method, which seems to make me think that there might be a way to force it to do that.

I did have a look at modifying the people picker input from the extension I linked above however no matter what I change it to, Sharepoint seems to realise that it is "wrong" and shares it the same way it expects.

0 Votes 0 ·

These external users were invited to your organization before, so they are guest users in SharePoint. You could check them in SharePoint admin center->users->Guest users. For guest users, using the ShareDocument method would treat them as internal users.

0 Votes 0 ·

@Aaeeschylus-2679,

You could consider using Graph api to grant users access to a sharing link. This would achieve your requirements
https://docs.microsoft.com/en-us/graph/api/permission-grant?view=graph-rest-1.0&tabs=http

0 Votes 0 ·

I have tried using Microsoft Graph and managed to get it to work. I ended up using a mixture of both CSOM and Graph. Thanks

0 Votes 0 ·