Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite thisSite = new SPSite(SPContext.Current.Site.WebApplication.AlternateUrls[0].Uri.AbsoluteUri))
                    {
                        html = "";
                        TaxonomySession session   = new TaxonomySession(thisSite);
                        TermStoreCollection store = session.TermStores;

                        try
                        {
                            foreach (TermStore termStore in session.TermStores)
                            {
                                Group navGroup = termStore.Groups["PORTAL"];
                                TermSet topSet = navGroup.TermSets["GlobalNav"];
                                html          += writeTerms(topSet.Terms);
                            }
                        }
                        catch
                        {
                        }

                        finally
                        {
                            RecordsNavContainer.Text = "";
                            RecordsNavContainer.Text = html;
                        }
                    }
                });
            }
        }
Пример #2
0
        public TermStoreCollectionInstance(ObjectInstance prototype, TermStoreCollection termStoreCollection)
            : this(prototype)
        {
            if (termStoreCollection == null)
            {
                throw new ArgumentNullException("termStoreCollection");
            }

            m_termStoreCollection = termStoreCollection;
        }
Пример #3
0
        /// <summary>
        /// Exports the full list of terms from all termsets in all termstores.
        /// </summary>
        /// <param name="includeId">if true, Ids of the the taxonomy items will be included</param>
        /// <param name="clientContext"></param>
        /// <param name="delimiter">if specified, this delimiter will be used. Notice that IDs will be delimited with ;# from the label</param>
        /// <returns></returns>
        public static List <string> ExportAllTerms(this Site site, bool includeId, string delimiter = "|")
        {
            var clientContext = site.Context;

            List <string> termsString = new List <string>();

            TaxonomySession taxonomySession = taxonomySession = TaxonomySession.GetTaxonomySession(clientContext);

            clientContext.ExecuteQuery();

            TermStoreCollection termStores = taxonomySession.TermStores;

            clientContext.Load(termStores, t => t.IncludeWithDefaultProperties(s => s.Groups));
            clientContext.ExecuteQuery();
            foreach (TermStore termStore in termStores)
            {
                foreach (TermGroup termGroup in termStore.Groups)
                {
                    TermSetCollection termSets = termGroup.TermSets;
                    clientContext.Load(termSets, t => t.IncludeWithDefaultProperties(s => s.Terms));
                    clientContext.ExecuteQuery();
                    string termGroupName = DenormalizeName(termGroup.Name);
                    string groupPath     = string.Format("{0}{1}", termGroupName, (includeId) ? string.Format(";#{0}", termGroup.Id.ToString()) : "");
                    foreach (TermSet set in termSets)
                    {
                        string setName     = DenormalizeName(set.Name);
                        string termsetPath = string.Format("{0}{3}{1}{2}", groupPath, setName, (includeId) ? string.Format(";#{0}", set.Id.ToString()) : "", delimiter);
                        foreach (Term term in set.Terms)
                        {
                            string termName = DenormalizeName(term.Name);
                            string termPath = string.Format("{0}{3}{1}{2}", termsetPath, termName, (includeId) ? string.Format(";#{0}", term.Id.ToString()) : "", delimiter);
                            termsString.Add(termPath);

                            if (term.TermsCount > 0)
                            {
                                string subTermPath = string.Format("{0}{3}{1}{3}{2}", groupPath, termsetPath, termName, delimiter);

                                termsString.AddRange(ParseSubTerms(subTermPath, term, includeId, delimiter, clientContext));
                            }
                        }
                    }
                }
            }

            return(termsString.Distinct().ToList <string>());
        }
Пример #4
0
        public static void UseSession(SPSite site)
        {
            TaxonomySession session = new TaxonomySession(site);


            // Get the default keyword TermStore for the provided site
            TermStore defaultKeywordStore = session.DefaultKeywordsTermStore;

            if (defaultKeywordStore != null)
            {
                Console.WriteLine(defaultKeywordStore.Name);
            }
            else
            {
                Console.WriteLine("Default keyword store is not configured or not configured properly");
            }


            // Get the default site collection TermStore associated with the provide site.
            TermStore defaultSiteCollectionStore = session.DefaultSiteCollectionTermStore;

            if (defaultSiteCollectionStore != null)
            {
                Console.WriteLine(defaultSiteCollectionStore.Name);
            }
            else
            {
                Console.WriteLine("Default site collection TermStore is not configured or not configured properly");
            }


            // Get all the TermStores associated with the provided site.
            TermStoreCollection termStores = session.TermStores;

            Console.WriteLine(termStores.Count);


            // Get all the offline TermStore names
            StringCollection names = session.OfflineTermStoreNames;

            Console.WriteLine(names.Count);


            // Resync the taxonomy hidden list to make sure it is update-to-date
            TaxonomySession.SyncHiddenList(site);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()

                {
                    ResourceManager rm     = new ResourceManager("SP2013.Custom.Branding.CustomBranding", Assembly.GetExecutingAssembly());
                    string error           = rm.GetString("TermError");
                    string errorServiceApp = rm.GetString("TermServiceAppError");
                    try
                    {
                        SPSite thisSite = new SPSite(SPContext.Current.Site.WebApplication.AlternateUrls[0].Uri.AbsoluteUri);

                        if (thisSite != null)
                        {
                            using (thisSite)
                            {
                                html = "";
                                TaxonomySession session   = new TaxonomySession(thisSite);
                                TermStoreCollection store = session.TermStores;


                                try
                                {
                                    foreach (TermStore termStore in session.TermStores)
                                    {
                                        //var string1 = termStore.Name.ToString();
                                        //Group navGroup = termStore.Groups["Custom SP2013 Navigation"];
                                        var string1       = termStore.Name.ToString();
                                        var termStoreName = Attributes["CustomTermStoreName"].ToString();
                                        Group navGroup    = termStore.Groups[termStoreName];

                                        foreach (TermSet topSet in navGroup.TermSets)
                                        {
                                            html += writeTerms(topSet.Terms);
                                        }
                                    }
                                }
                                catch
                                {
                                    html = error;;
                                }

                                finally
                                {
                                    Custom_SP2013_GlobalNavContainer_Keyboard.Text = "";
                                    Custom_SP2013_GlobalNavContainer_Keyboard.Text = html;
                                }
                            }
                        }
                    }
                    catch
                    {
                        html = errorServiceApp;
                        Custom_SP2013_GlobalNavContainer_Keyboard.Text = html;
                    }

                    finally
                    {
                        Custom_SP2013_GlobalNavContainer_Keyboard.Text = html;
                    }
                });
            }
        }
Пример #6
0
        public void ImportTermStore(TermStoreCollection termStoreCollection, XElement termStoreElement, bool recurse = true)
        {
            try
            {
                //Get the term store name
                string termStoreName = (string)termStoreElement.Attribute("Name");

                //Check if term store exists
                TermStore termStore = (from termstore in termStoreCollection where termstore.Name == termStoreName select termstore).SingleOrDefault();

                //TODO: If the term store is not there, create it
                if(termStore == null)
                {
                    throw new Exception("Term Store not found. Please create the term store from central admin");
                }

                if (recurse)
                {
                    foreach (XElement childElement in termStoreElement.Elements())
                    {
                        ImportGroup(termStore, childElement, recurse);
                    }
                }

                termStore.CommitAll();
            }
            catch(Exception e)
            {
            }
        }
Пример #7
0
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Enter your user name");
            // Console.ForegroundColor = defaultForeground;
            string userName = Console.ReadLine();

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Enter your password.");
            // Console.ForegroundColor = defaultForeground;
            SecureString password = GetPasswordFromConsoleInput();

            using (context = new ClientContext("https://microsoft.sharepoint.com/teams/USDXISVCJ/"))
            {
                context.Credentials = new SharePointOnlineCredentials(userName, password);
                Web currentWeb = context.Web;
                context.Load(currentWeb);
                context.ExecuteQuery();

                TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(currentWeb.Context);

                TermStoreCollection termStores = taxonomySession.TermStores;

                currentWeb.Context.Load(termStores);

                currentWeb.Context.ExecuteQuery();

                TermStore termStore = termStores[0];

                currentWeb.Context.Load(termStore);

                currentWeb.Context.ExecuteQuery();

                TermGroupCollection termGroups = termStore.Groups;

                currentWeb.Context.Load(termGroups);

                currentWeb.Context.ExecuteQuery();

                TermGroup group = termGroups.GetByName("Site Collection - microsoft.sharepoint.com-teams-USDXISVCJ");

                TermSetCollection termSets = group.TermSets;

                currentWeb.Context.Load(termSets);

                currentWeb.Context.ExecuteQuery();

                TermCollection terms = termSets.GetByName("Workload").Terms;

                currentWeb.Context.Load(terms);

                currentWeb.Context.ExecuteQuery();

                Console.WriteLine(terms.Count);

                foreach (Term term in terms)
                {
                    Console.WriteLine(term.Name);
                }
            }
        }