I'm using the SharePoint Client Object Model to login into SharePoint online and then retrieve the Lists to get Documents on SharePoint. I then want to get the shared link for these documents. Here's how I am doing it at the moment:
using (var context = new ClientContext(siteURL))
{
context.Credentials = new SharePointOnlineCredentials(login, securePassword);
context.Load(context.Web, w => w.Title);
context.ExecuteQuery();
List docList = context.Web.Lists.GetByTitle("Documents");
context.Load(docList);
// This creates a CamlQuery that has a RowLimit of 100, and also specifies Scope="RecursiveAll"
// so that it grabs all list items, regardless of the folder they are in.
CamlQuery query = CamlQuery.CreateAllItemsQuery(100);
ListItemCollection items = docList.GetItems(query);
// Retrieve all items in the ListItemCollection from List.GetItems(Query).
context.Load(items);
context.ExecuteQuery();
foreach (ListItem listItem in items)
{
var sharingInfo = ObjectSharingInformation.GetListItemSharingInformation(
context, docList.Id, listItem.Id, false, true, false, true, true, true);
context.Load(sharingInfo);
context.ExecuteQuery();
string str = sharingInfo.AnonymousEditLink;
}
}
The issue here is that sharingInfo object has a field called AnonymousEditLink but it is an empty string. I'm not sure why this is an empty string. Is this the right way of going about generating a sharing link?
I have also tried this (but to no avail):
var sharingInfo = ObjectSharingInformation.GetObjectSharingInformation(
context, listItem, false, true, false, true, true, true, true);
I am referring to the method shown here: https://sharepoint.stackexchange.com/questions/143612/how-to-retrieve-the-shared-link-of-a-file-programmatically