Question

I was trying to get the URL of a document (inside document library) link same as Get a Link option with View (account required).I am using following code with sharing options. SharingInfo object does not have such view link and it is more to sharing document with permission.

var sharingInfo = ObjectSharingInformation.GetObjectSharingInformation(
clientContext, item, false, true, false, true, true, true, true);
clientContext.Load(sharingInfo);
clientContext.ExecuteQuery();

SharingInfo only provides anonymous links only

sharingInfo.AnonymousEditLink 
sharingInfo.AnonymousViewLink

What is the correct way to fetch Get a link Urls using c# client object mode .Is this possible?

enter image description here

Was it helpful?

Solution 2

There is a method available in Web (CSOM) to get share link.I have solved it by using this method

    public static ClientResult<string> CreateOrganizationSharingLink(
     ClientRuntimeContext context,
     string url,
     bool isEditLink
    )

Refer https://msdn.microsoft.com/EN-US/library/microsoft.sharepoint.client.web.createorganizationsharinglink.aspx for more details

OTHER TIPS

You can use the GetWOPIFrameUrl method to get that URL.

If you know the Server Relative URL of the file, you can use it as below:

Microsoft.SharePoint.Client.File file = context.Web.GetFileByServerRelativeUrl("/sites/test/Shared Documents/abcd.docx");

var viewLink = file.ListItemAllFields.GetWOPIFrameUrl(SPWOPIFrameAction.View);

context.Load(file, f => f.ListItemAllFields);
context.ExecuteQuery();

var value = viewLink.Value;

If you know the list item's ID or the list item object, you can use it as below:

Microsoft.SharePoint.Client.ListItem item = context.Web.Lists.GetByTitle("Documents").GetItemById(1);

var viewLink = item.GetWOPIFrameUrl(SPWOPIFrameAction.View);

context.Load(item);
context.ExecuteQuery();

var value = viewLink.Value;

Reference - ListItem.GetWOPIFrameUrl method

SPWOPIAction enumeration

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top