Programmatically get the list of URL’s of site collections that have read-only access

I have a site collection http://c4968397007/ in which I have created a local taxonomy group. Navigate to the site collection http://c4968397007/. Click on Settings, and then click on Site Settings.

Click on Term store management which is available under Site Administration section. You could be able to see the local site collection taxonomy group in the Taxonomy Term Store.

 

In SharePoint 2013, local term sets can be exposed to other site collections. This is one of the improvements in SharePoint 2013. Please refer http://www.c-sharpcorner.com/UploadFile/anavijai/cross-site-collection-term-set-access-in-sharepoint-2013/ to know more about cross site collection term set access in SharePoint 2013. In my last article I have mentioned how to add the site collections to have read only access to the local site collection taxonomy group in SharePoint 2013 using server object model.

 

In this blog you will see how to get the list of URL's of site collections that have read-only access to the local site collection taxonomy group using SharePoint Object Model.


using System;

using System.Collections.Generic;

using System.Collections.ObjectModel;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using Microsoft.SharePoint;

using Microsoft.SharePoint.Taxonomy;

 

namespace TaxonomyCodeSamples

{

    class Program

    {

        static void Main(string[] args)

        {          

            using (SPSite site = new SPSite("http://c4968397007/"))

            {

                TaxonomySession taxSession = new TaxonomySession(site);

                //// Get the term store

                TermStore termStore = taxSession.TermStores["MMS"];

                //// Get the local site collection taxonomy group

                Group group = termStore.GetSiteCollectionGroup(site);

                //// Gets a list of URLs of site collections that have read-only access.

                ReadOnlyCollection<string> urls = group.SiteCollectionReadOnlyAccessUrls;

                foreach (string url in urls)

                {

                    //// Display the site collection URL that have read only access

                    Console.WriteLine(url);

                }

                Console.ReadLine();

            }

        }    

    }

}


 

Ebook Download
View all
Learn
View all