{"id":5362,"date":"2019-08-20T10:23:53","date_gmt":"2019-08-20T10:23:53","guid":{"rendered":"https:\/\/www.softreetechnology.com\/?p=5362"},"modified":"2019-08-20T10:23:53","modified_gmt":"2019-08-20T10:23:53","slug":"retrieve-sharing-links-information-for-a-sharepoint-item-using-csom","status":"publish","type":"post","link":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-sharing-links-information-for-a-sharepoint-item-using-csom\/","title":{"rendered":"Retrieve Sharing Links Information For A SharePoint Item Using CSOM"},"content":{"rendered":"\n<p>There is no direct method present in item object to get \/retrieve the sharing links information, we can get item sharing links information by using &#8216;ObjectSharingInformation&#8217; class. We can get the &#8216;AnonymousEditLink&#8217;, &#8216;AnonymousViewLink&#8217; and &#8216;SharedWithUsersCollection&#8217; details using &#8216;ObjectSharingInformation&#8217;.<\/p>\n\n\n\n<p>In my below example I have mentioned all the steps how to retrieve all sharing links details and Shared User details for a SharePoint list item using CSOM programmatically. I have configured both &#8216;AnonymousEditLink&#8217;, &#8216;AnonymousViewLink&#8217; for the item used in the below example.<\/p>\n\n\n\n<p>I have used a simple console application to get all sharing links information for an SP list item. You can also get information like, sharing link creating date, expiration date, and many other properties by using &#8216;SharingLinkInfo&#8217; object.<\/p>\n\n\n\n<p><strong><span style=\"text-decoration: underline;\"> The code block for this is mentioned below. <\/span><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using System;  \nusing OfficeDevPnP.Core;  \nusing OfficeDevPnP.Core.Pages;  \nusing Microsoft.SharePoint.Client;  \nusing System.Security;  \nnamespace ConsoleApp4 {  \n    class Program {  \n        static void Main(string[] args) {  \n            Web web = null;  \n            List list = null;  \n            ClientContext ctx = null;  \n            ObjectSharingInformation sharingInfo = null;  \n            string siteUrl = string.Empty;  \n            string userName = string.Empty;  \n            string password = string.Empty;  \n            \/\/Site Url to scan  \n            siteUrl = \"https:\/\/softreetechnologytesting.sharepoint.com\/sites\/BibhutiTestSite\";  \n            \/\/Login User name  \n            userName = \"bibhuti.dakua@softreetechnologytesting.onmicrosoft.com\";  \n            \/\/Login password  \n            password = \"Softree2016\";  \n            \/\/Creating SharePoint Client Context  \n            using(ctx = new ClientContext(siteUrl)) {  \n                try {  \n                    SecureString passWord = new SecureString();  \n                    foreach(char c in password.ToCharArray())  \n                    passWord.AppendChar(c);  \n                    ctx.Credentials = new SharePointOnlineCredentials(userName, passWord);  \n                    web = ctx.Web;  \n                    \/\/loading sharepoint web instance  \n                    ctx.Load(web);  \n                    ctx.ExecuteQueryRetry();  \n                    \/\/get list by using list name  \n                    list = web.Lists.GetByTitle(\"Documents\");  \n                    \/\/ This will get first 100 items from the list including folders.  \n                    CamlQuery query = CamlQuery.CreateAllItemsQuery(100);  \n                    ListItemCollection items = list.GetItems(query);  \n                    \/\/ Retrieve items from List  \n                    ctx.Load(items, Itms => Itms.Include(Itm => Itm.Id));  \n                    ctx.ExecuteQuery();  \n                    if (items != null &amp;&amp; items.Count > 0) {  \n                        foreach(ListItem item in items) {  \n                            try {  \n                                sharingInfo = ObjectSharingInformation.GetObjectSharingInformation(ctx, item, false, true, false, true, true, true, true);  \n                                ctx.Load(sharingInfo);  \n                                ctx.ExecuteQuery();  \n                                \/\/ Getting Anonymous Edit Link from sharing object  \n                                string anonymousEditLink = sharingInfo.AnonymousEditLink;  \n                                \/\/ Getting Anonymous View Link from sharing object  \n                                string anonymousViewLink = sharingInfo.AnonymousViewLink;  \n                                if (sharingInfo != null &amp;&amp; sharingInfo.SharedWithUsersCollection != null) {  \n                                    \/\/ Looping all shared users information from ObjectSharingInformation  \n                                    foreach(ObjectSharingInformationUser sharingUser in sharingInfo.SharedWithUsersCollection) {  \n                                        try {  \n                                            if (!string.IsNullOrEmpty(sharingUser.LoginName)) {  \n                                                string sharingUserLoginName = sharingUser.LoginName;  \n                                                Console.WriteLine(\"Shared User Login Name: \" + sharingUserLoginName);  \n                                            }  \n                                        } catch (Exception ex) {}  \n                                    }  \n                                }  \n                                if (sharingInfo != null &amp;&amp; sharingInfo.SharingLinks != null) {  \n                                    \/\/ Looping all sharing links from ObjectSharingInformation  \n                                    foreach(SharingLinkInfo sharingLinkInfo in sharingInfo.SharingLinks) {  \n                                        try {  \n                                            if (!string.IsNullOrEmpty(sharingLinkInfo.Url)) {  \n                                                string sharingLink = sharingLinkInfo.Url;  \n                                                Console.WriteLine(\"Sharing Link Url: \" + sharingLink);  \n                                            }  \n                                        } catch (Exception ex) {}  \n                                    }  \n                                }  \n                            } catch (Exception ex) {}  \n                        }  \n                    }  \n                    Console.ReadLine();  \n                } catch (Exception ex) {}  \n            }  \n        }  \n    }  \n}  <\/code><\/pre>\n\n\n\n<p> To verify the retrieved shared links&#8217; value, you can compare those with the original ones. <\/p>\n\n\n\n<p><strong>This solution is brought to you by our SharePoint professionals.<\/strong><\/p>\n\n\n\n<p><strong><a href=\"https:\/\/www.softreetechnology.com\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"Softree Technology (opens in a new tab)\">Softree Technology<\/a><\/strong> employs SharePoint consultants; we are a technology services provider with the aim to help companies achieve exceptional performance through SharePoint. Our dedicated team of SharePoint consultants has the right bent of mind to understand and execute customer requirements.<\/p>\n\n\n\n<p>Be it SPFx or SharePoint add-in developments, SharePoint 2019 developments, web part developments, migrating from SharePoint 2010\/2013 to SharePoint 2013\/2016\/Office 365, Office 365, SharePoint hosted apps development or something else in SharePoint, we strive to deliver the best<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There is no direct method present in item object to get \/retrieve the sharing links information, we can get item sharing links information by using &#8216;ObjectSharingInformation&#8217; class. We can get the &#8216;AnonymousEditLink&#8217;, &#8216;AnonymousViewLink&#8217; and &#8216;SharedWithUsersCollection&#8217; details using &#8216;ObjectSharingInformation&#8217;. In my below example I have mentioned all the steps how to retrieve all sharing links details and Shared User details for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[105,106,107,168,108,159],"class_list":["post-5362","post","type-post","status-publish","format-standard","hentry","category-sharepoint","tag-get-sharing-links-for-sharepoint-online","tag-get-sharing-links-information-using-object-model-in-spo","tag-get-sharing-links-using-csom","tag-office-365","tag-retrieve-shared-users-information-from-a-sharepoint-file","tag-sharepoint-online"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Retrieve Sharing Links Information For A SharePoint Item Using CSOM - Softree Technology<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-sharing-links-information-for-a-sharepoint-item-using-csom\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Retrieve Sharing Links Information For A SharePoint Item Using CSOM - Softree Technology\" \/>\n<meta property=\"og:description\" content=\"There is no direct method present in item object to get \/retrieve the sharing links information, we can get item sharing links information by using &#8216;ObjectSharingInformation&#8217; class. We can get the &#8216;AnonymousEditLink&#8217;, &#8216;AnonymousViewLink&#8217; and &#8216;SharedWithUsersCollection&#8217; details using &#8216;ObjectSharingInformation&#8217;. In my below example I have mentioned all the steps how to retrieve all sharing links details and Shared User details for [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-sharing-links-information-for-a-sharepoint-item-using-csom\/\" \/>\n<meta property=\"og:site_name\" content=\"Softree Technology\" \/>\n<meta property=\"article:published_time\" content=\"2019-08-20T10:23:53+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Retrieve Sharing Links Information For A SharePoint Item Using CSOM - Softree Technology","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-sharing-links-information-for-a-sharepoint-item-using-csom\/","og_locale":"en_US","og_type":"article","og_title":"Retrieve Sharing Links Information For A SharePoint Item Using CSOM - Softree Technology","og_description":"There is no direct method present in item object to get \/retrieve the sharing links information, we can get item sharing links information by using &#8216;ObjectSharingInformation&#8217; class. We can get the &#8216;AnonymousEditLink&#8217;, &#8216;AnonymousViewLink&#8217; and &#8216;SharedWithUsersCollection&#8217; details using &#8216;ObjectSharingInformation&#8217;. In my below example I have mentioned all the steps how to retrieve all sharing links details and Shared User details for [&hellip;]","og_url":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-sharing-links-information-for-a-sharepoint-item-using-csom\/","og_site_name":"Softree Technology","article_published_time":"2019-08-20T10:23:53+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-sharing-links-information-for-a-sharepoint-item-using-csom\/#article","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-sharing-links-information-for-a-sharepoint-item-using-csom\/"},"author":{"name":"admin","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/98740297642f06debccdcee2de84086b"},"headline":"Retrieve Sharing Links Information For A SharePoint Item Using CSOM","datePublished":"2019-08-20T10:23:53+00:00","mainEntityOfPage":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-sharing-links-information-for-a-sharepoint-item-using-csom\/"},"wordCount":236,"commentCount":0,"publisher":{"@id":"https:\/\/softreetechnology.com\/blog\/#organization"},"keywords":["Get sharing links for SharePoint Online","Get sharing links information using object model in SPO","Get sharing links using csom","office 365","Retrieve Shared Users information from a SharePoint file","SharePoint Online"],"articleSection":["SharePoint"],"inLanguage":"en","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-sharing-links-information-for-a-sharepoint-item-using-csom\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-sharing-links-information-for-a-sharepoint-item-using-csom\/","url":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-sharing-links-information-for-a-sharepoint-item-using-csom\/","name":"Retrieve Sharing Links Information For A SharePoint Item Using CSOM - Softree Technology","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/#website"},"datePublished":"2019-08-20T10:23:53+00:00","breadcrumb":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-sharing-links-information-for-a-sharepoint-item-using-csom\/#breadcrumb"},"inLanguage":"en","potentialAction":[{"@type":"ReadAction","target":["https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-sharing-links-information-for-a-sharepoint-item-using-csom\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/retrieve-sharing-links-information-for-a-sharepoint-item-using-csom\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/softreetechnology.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Retrieve Sharing Links Information For A SharePoint Item Using CSOM"}]},{"@type":"WebSite","@id":"https:\/\/softreetechnology.com\/blog\/#website","url":"https:\/\/softreetechnology.com\/blog\/","name":"Softree Technology","description":"Celebrating 10+ Years in SharePoint Consulting !","publisher":{"@id":"https:\/\/softreetechnology.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/softreetechnology.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en"},{"@type":"Organization","@id":"https:\/\/softreetechnology.com\/blog\/#organization","name":"Softree Technology","url":"https:\/\/softreetechnology.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/softreetechnology.com\/blog\/wp-content\/uploads\/2023\/03\/cropped-white-logo-soft.png","contentUrl":"https:\/\/softreetechnology.com\/blog\/wp-content\/uploads\/2023\/03\/cropped-white-logo-soft.png","width":844,"height":230,"caption":"Softree Technology"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/98740297642f06debccdcee2de84086b","name":"admin","image":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6fc78c8a7aa3fb0bf43c3b9a2e3962d7?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6fc78c8a7aa3fb0bf43c3b9a2e3962d7?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/softreeconsulting.com"],"url":"https:\/\/softreetechnology.com\/blog\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts\/5362","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/comments?post=5362"}],"version-history":[{"count":0,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts\/5362\/revisions"}],"wp:attachment":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/media?parent=5362"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/categories?post=5362"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/tags?post=5362"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}