0

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

1

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

0

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

  • Hello ,Can you please share little bit more on this .I have an exact requirement where i need to get the Edit link and View links for documents created – Anil Aug 27 '18 at 20:41

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.