I currently have a program that will upload selected files to a specific folder on SharePoint and give access to specific users based on their emails using the SharePoint CSOM API, however, I am unable to generate the links for people outside of my domain.

For example: I get


instead of


I am currently retrieving the first link by using the code from here: https://www.c-sharpcorner.com/article/generating-sharing-links-report-and-removing-sharing-links-using-sharepoint-onli/

I have also tried other suggestions I have found on StackExchange such as Manage links for shared files

All examples I have found like the above all result in the incorrect links.

In case it is not clear currently, I am not after an anonymous link or how to create shared links (as I already have this working), I am after the link that would appear here:

enter image description here


I managed to find the solution after just randomly trying everything. What you can do is as follows:

First, create the sharing link in the way I was previously:

SharingResult result = context.Web.ShareDocument(site,
                       "Document Shared as test");

Then with the result variable, grab the invitation link of one of the invited users and then modify it to work for any user (as it turns out, specific links are the same for all users other than a parameter on the end)

string link = result.InvitedUsers.FirstOrDefault().
int index = link.IndexOf("?");
if (index > 0) link = link.Substring(0, index);

This results in the correct link I was looking for. I did speak to some people from Microsoft asking about this, so, thanks Microsoft for telling me this was impossible!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.