I am using C# to programmatically access files on our Office 365 SharePoint site using the Microsoft.Sharepoint.Client.dll. In one of our shared folders all the documents are Shared with anyone with a link (i.e. https://mycompany.sharepoint.com/_layouts/15/guestaccess.aspx?guestaccesstoken=QRsbIP0XzXC9%2bONJWf8tqXCTmIUq2n04JArVh%2bm1dnw%3d&docid=02fecf600149d41fc85b13fca96af9467 Is it possible to retrieve this link programmatically? I can get the URL of the file without a problem but need the URL of the shared link.

My code so far:

//using our client context, load the folder of the files we want links to
Folder folder = Program.spConnection.context.Web.GetFolderByServerRelativeUrl(Properties.Settings.Default.SPImages);

FileCollection filec = folder.Files;

List<string> allSharedURLs = new List<string>();
//Load Each File in the folder
foreach (File f in filec)

    // I would like to add the publically shared url to the list at this point
    // allSharedURLs.Add( theLink );    

If the user who you are Sharing File is part of SharePoint then you can simply pass the URL to the user, who can access the file directly.

For external users, you can get this link using ObjectSharingInformation class. This class has property AnonymousEditLink and AnonymousViewLink

You can use below snippet for that

var item = //code to get list item..
var objSharingInfo = ObjectSharingInformation.GetObjectSharingInformation(
        clientContext, item, false, true, false, true, true, true, true);
| improve this answer | |
  • Hi @Amal Hashim! I get "ObjectSharingInformation is not defined" every time. Does it work for You in Sp Online in 2018? – Gennady G Sep 6 '18 at 11:26

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.