Ejemplo n.º 1
0
        public static void CreateTaxonomyFavColor(ClientContext ctx)
        {
            TermStore store = ctx.Site.GetDefaultSiteCollectionTermStore();

            TermGroup group = store.GetTermGroupByName("School");

            if (group == null)
            {
                group = store.CreateTermGroup("School", "{13E6924A-196D-4313-A1B4-3A21AF3958CF}".ToGuid(), "description");
            }
            TermSet termSet = group.EnsureTermSet("Fav Color", "{3D4C7DE0-3867-44C3-871A-C36DEC4E1970}".ToGuid(), 1033);


            Term term = store.GetTerm("{1BB08D14-4464-410C-A27C-BA2EB8EFE9DE}".ToGuid());

            ctx.Load(term);
            ctx.ExecuteQuery();

            if (term.ServerObjectIsNull())
            {
                termSet.CreateTerm("Green", 1033, "{1BB08D14-4464-410C-A27C-BA2EB8EFE9DE}".ToGuid());
                termSet.CreateTerm("Blue", 1033, "{E96EF7E0-7F9B-4F66-BA1A-C2DBCC73DD78}".ToGuid());
                termSet.CreateTerm("Red", 1033, "{13E22744-483D-49D2-B92D-6BD2E0C10D9C}".ToGuid());
                ctx.ExecuteQuery();
            }
        }
Ejemplo n.º 2
0
        public static void CreateIssueCategoryTermSet(ClientContext ctx)
        {
            //TaxonomySession taxSession = TaxonomySession.GetTaxonomySession(ctx);
            //TermStore store = taxSession.TermStores[0];
            TermStore store = ctx.Site.GetDefaultSiteCollectionTermStore();

            TermGroup group = store.GetTermGroupByName("OD1Test");

            if (group == null)
            {
                group = store.CreateTermGroup("OD1Test", "{13E6924A-196D-4313-A1B4-3A21AF3958CF}".ToGuid(), "description");
            }
            TermSet termSet = group.EnsureTermSet("Issue Category", "{3D4C7DE0-3867-44C3-871A-C36DEC4E1970}".ToGuid(), 1033);


            Term term = store.GetTerm("{1BB08D14-4464-410C-A27C-BA2EB8EFE9DE}".ToGuid());

            ctx.Load(term);
            ctx.ExecuteQuery();

            if (term == null)
            {
                termSet.CreateTerm("Just Right", 1033, "{1BB08D14-4464-410C-A27C-BA2EB8EFE9DE}".ToGuid());
                termSet.CreateTerm("Low Priority", 1033, "{E96EF7E0-7F9B-4F66-BA1A-C2DBCC73DD78}".ToGuid());
                termSet.CreateTerm("Urgent", 1033, "{13E22744-483D-49D2-B92D-6BD2E0C10D9C}".ToGuid());

                ctx.ExecuteQuery();
            }
        }
Ejemplo n.º 3
0
        //ModifyItem
        //CreateTermSet
        public void CreateTermSet(ClientContext context)
        {
            //English(Default English Locale ID)
            int lcid = 1033;
            //Get termSession
            TaxonomySession taxonomy = TaxonomySession.GetTaxonomySession(context);

            if (taxonomy != null)
            {
                //Get TermStore
                TermStore termStore = taxonomy.GetDefaultKeywordsTermStore();
                if (termStore != null)
                {
                    //Set TermGroup
                    TermGroup termGroup = termStore.CreateGroup(TERMGROUPNAME, Guid.NewGuid());
                    //Set TermSet
                    TermSet termSetCollection = termGroup.CreateTermSet(TERMSETNAME, Guid.NewGuid(), lcid);
                    //Set Terms
                    termSetCollection.CreateTerm(TERM_ELEKTRONIK, lcid, Guid.NewGuid());
                    termSetCollection.CreateTerm(TERM_FORDON, lcid, Guid.NewGuid());
                    termSetCollection.CreateTerm(TERM_FRITIDOCHHOBBY, lcid, Guid.NewGuid());
                    termSetCollection.CreateTerm(TERM_HYGIENARTIKLAR, lcid, Guid.NewGuid());
                    termSetCollection.CreateTerm(TERM_MÖBLER, lcid, Guid.NewGuid());

                    context.ExecuteQuery();
                }
            }
        }
Ejemplo n.º 4
0
        public static void CreateProductTaxonomy(ClientContext ctx)
        {
            TermStore store = ctx.Site.GetDefaultKeywordsTermStore();
            TermGroup productCategoryGroup = store.GetTermGroupByName("OD2");

            if (productCategoryGroup == null)
            {
                productCategoryGroup = store.CreateTermGroup("OD2", Constants.TAXONOMY_OD2_GROUP_ID.ToGuid(), "Stuff for od2");
            }


            TermSet ts = store.GetTermSet(Constants.TAXONOMY_PRODUCTCAT_TERMSET_ID.ToGuid());

            ctx.Load(ts);
            ctx.ExecuteQuery();
            // if term store does not exist create a new one.
            if (ts.ServerObjectIsNull.Value)
            {
                ts = productCategoryGroup.CreateTermSet("Product Category", Constants.TAXONOMY_PRODUCTCAT_TERMSET_ID.ToGuid(), 1033);
                store.CommitAll();
                ctx.Load(ts);
                ctx.ExecuteQuery();
                ts.CreateTerm("Prod Cat 1", 1033, Guid.NewGuid());
                ts.CreateTerm("Prod Cat 2", 1033, Guid.NewGuid());
                ts.CreateTerm("Prod Cat 3", 1033, Guid.NewGuid());
                ts.CreateTerm("Prod Cat 4", 1033, Guid.NewGuid());

                store.CommitAll();
                ctx.ExecuteQuery();
            }
        }
        private void CreatePlantTaxonomy(string contextToken, string hostWeb)
        {
            using (var clientContext
                       = TokenHelper.GetClientContextWithContextToken(hostWeb, contextToken, Request.Url.Authority))
            {
                //Create Taxonomy
                //To manage terms, we must create a new Taxonomy Session object
                TaxonomySession session = TaxonomySession.GetTaxonomySession(clientContext);

                //Get the termstore
                //TermStore termstore = session.TermStores["Managed Metadata Service"];
                TermStore termStore = session.GetDefaultSiteCollectionTermStore();

                //Create a term group
                //Group plantsGroup = termstore.CreateGroup("Plants", Guid.NewGuid());
                TermGroup plantsGroup = termStore.CreateGroup("Plants", Guid.NewGuid());

                //Create a term set
                TermSet flowersTermSet = plantsGroup.CreateTermSet("Flowers", Guid.NewGuid(), 1033);

                //Create some terms
                Term tulipsTerm    = flowersTermSet.CreateTerm("Tulips", 1033, Guid.NewGuid());
                Term orchidsTerm   = flowersTermSet.CreateTerm("Orchids", 1033, Guid.NewGuid());
                Term daffodilsTerm = flowersTermSet.CreateTerm("Daffodils", 1033, Guid.NewGuid());

                //Create a child term within the Orchids term
                Term vanillaTerm = orchidsTerm.CreateTerm("Vanilla", 1033, Guid.NewGuid());

                //You should set properties for every term. In this example, we'll
                //do just one for brevity
                vanillaTerm.SetDescription("A common orchid whose pods are used in desserts", 1033);
                //Use CreateLabel to add synomyns and alternates
                vanillaTerm.CreateLabel("Vanilla planifolia", 1033, false);
                vanillaTerm.CreateLabel("Flat-leaved vanilla", 1033, false);

                //When we are finished making changes, we must commit them
                try
                {
                    //termstore.CommitAll();
                    clientContext.ExecuteQuery();
                    resultsLabel.Text = "Taxonomy created successfully";
                }
                catch (Exception ex)
                {
                    resultsLabel.Text = "There was an error: " + ex.Message;
                }
            }
        }
Ejemplo n.º 6
0
        public void ImportTerm(TermSet termSet, XElement termElement, bool recurse = true)
        {
            try
            {
                //Get the term name
                string termName = (string)termElement.Attribute("Name");

                //Check if the term exist
                Term term = termSet.GetTerms(termName, false).FirstOrDefault();

                //If the term does not exist, create it
                if (term == null)
                {
                    int lcid = CultureInfo.CurrentCulture.LCID;
                    term = termSet.CreateTerm(termName, lcid);
                }

                //Create the child terms
                if (recurse)
                {
                    foreach (XElement childElement in termElement.Elements())
                    {
                        ImportTerm(term, childElement, recurse);
                    }
                }
            }
            catch (Exception e)
            {
            }
        }
Ejemplo n.º 7
0
        public static bool mk_NOR(TermStore termstore, string _group, string _termset, string _nor)
        {
            LogHelper logger = LogHelper.Instance;
            
            bool _result = false;
            try
            {
                TermSet termset = termstore.GetTermSet(GetIdTermSet(termstore, _group, _termset));

                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    Term term = termset.CreateTerm(_nor, termstore.DefaultLanguage);
                    termset.TermStore.CommitAll();
                });

                _result = true;
                logger.Log(string.Format("Normativa {0} creata nel Set {1}", _nor, _termset, LogSeverity.Debug));
            }
            catch (Exception ex)
            {
                _result = false;
                logger.Log(ex.Message + " : " + string.Format("Normativa {0} non creata nel Set {1}", _nor, _termset, LogSeverity.Error));
            }
            return _result;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Create client terms
        /// </summary>
        /// <param name="TermsData">Data for client terms</param>
        /// <param name="clientContext">Client Context object</param>
        private static void CreateTermsForClients(List <CustomClientGroup> TermsData, ClientContext clientContext)
        {
            TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(clientContext);

            clientContext.Load(taxonomySession.TermStores);

            //Execute the query to the server
            clientContext.ExecuteQuery();
            TermStore termStore = taxonomySession.GetDefaultSiteCollectionTermStore();

            clientContext.Load(termStore.Groups);

            //Execute the query to the server
            clientContext.ExecuteQuery();
            foreach (CustomClientGroup cltGroup in TermsData)
            {
                TermGroup group = termStore.Groups.Where(termGroup => termGroup.Name == cltGroup.name).Count() > 0 ? termStore.Groups.GetByName(cltGroup.name) : termStore.CreateGroup(cltGroup.name, Guid.NewGuid());
                if (null != group)
                {
                    TermSet cltTermSet   = group.CreateTermSet(ConfigurationManager.AppSettings["clientterm"], Guid.NewGuid(), 1033);
                    TermSet cltIDTermSet = group.CreateTermSet(ConfigurationManager.AppSettings["clientidterm"], Guid.NewGuid(), 1033);
                    foreach (ClientList clients in cltGroup.clt)
                    {
                        Term clientCustom = cltTermSet.CreateTerm(clients.ClientName, 1033, Guid.NewGuid());
                        cltIDTermSet.CreateTerm(clients.ClientID, 1033, Guid.NewGuid());
                        clientCustom.SetCustomProperty("ClientID", clients.ClientID);
                        clientCustom.SetCustomProperty("ClientURL", clients.ClientURL);
                    }
                }
            }
            termStore.CommitAll();
            clientContext.Load(termStore);
            //Execute the query to the server
            clientContext.ExecuteQuery();
        }
Ejemplo n.º 9
0
        public static void CreateTaxonomy(ClientContext ctx)
        {
            TermStore store = ctx.Site.GetDefaultSiteCollectionTermStore();

            TermGroup group = store.GetGroup("{0671B184-F909-4DCA-B383-6E05C969BEF1}".ToGuid());

            ctx.Load(group);
            ctx.ExecuteQuery();
            if (group.ServerObjectIsNull())
            {
                group = store.CreateTermGroup("David1", "{0671B184-F909-4DCA-B383-6E05C969BEF1}".ToGuid());
            }

            TermSet ts = group.EnsureTermSet("Color", "{19419441-6982-4978-8800-F12A46E6FE37}".ToGuid(), 1033);

            // Term term = ts.CreateTerm("Green", 1033, "{FA6628FA-9790-4622-9B54-23D103A67FCD}".ToGuid());
            // Term term2 = ts.CreateTerm("Röd", 1053, "{24FA5756-25E8-4257-A4E5-D53C3D48B595}".ToGuid());
            // ctx.ExecuteQuery();

            // term2.EnsureLabel(1033, "Red", false);

            Term term2 = ts.CreateTerm("Blue", 1033, "{73E90F88-BD96-4066-8237-2D0DAAE3F11C}".ToGuid());

            ctx.ExecuteQuery();

            term2.EnsureLabel(1053, "Blå", false);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Updates a single-value managed metatada column
        /// </summary>
        /// <param name="taxonomyTerm"></param>
        /// <param name="item"></param>
        /// <param name="fieldToUpdate"></param>
        public static void UpdateMMField(string taxonomyTerm, SPListItem item, string fieldToUpdate)
        {
            //Get the metadata taxonomy field, a taxonomy session, the term store, and a collection of term sets in the store
            TaxonomyField   managedMetadataField = item.ParentList.Fields[fieldToUpdate] as TaxonomyField;
            Guid            tsId        = managedMetadataField.TermSetId;
            Guid            termStoreId = managedMetadataField.SspId;
            TaxonomySession tSession    = new TaxonomySession(item.ParentList.ParentWeb.Site);
            TermStore       tStore      = tSession.TermStores[termStoreId];
            TermSet         tSet        = tStore.GetTermSet(tsId);
            TermCollection  terms       = tSet.GetTerms(taxonomyTerm, false);
            Term            term        = null;

            //If term doesn't exist, create it in the term store
            if (terms.Count == 0)
            {
                Console.WriteLine("Creating term in managed metadata, {0}", taxonomyTerm);
                term = tSet.CreateTerm(taxonomyTerm, tStore.Languages[0]);
                tStore.CommitAll();
            }
            else
            {
                term = terms[0];
            }

            //Set the managed metadata field to the term retrieved from the term store
            managedMetadataField.SetFieldValue(item, term);
            item.Update();
        }
        /// <summary>
        /// TermSet に Term を追加します。
        /// </summary>
        /// <param name="this">TermSet</param>
        /// <param name="name">名前</param>
        /// <param name="lcid">ID</param>
        /// <param name="action">追加した Term を加工する関数</param>
        /// <returns>TermSet を返します。</returns>
        public static TermSet AddTerm(this TermSet @this, string name, int lcid, Action <Term> action = null)
        {
            var tm = @this.CreateTerm(name, lcid, Guid.NewGuid());

            action?.Invoke(tm);

            return(@this);
        }
Ejemplo n.º 12
0
    static void CreateTerms(ClientContext clientContext, TermSet termSet) {

      Term termEurope = termSet.CreateTerm("Europe", 1033, Guid.NewGuid());
      termEurope.CreateTerm("United Kingdon", 1033, Guid.NewGuid());
      termEurope.CreateTerm("France", 1033, Guid.NewGuid());
      termEurope.CreateTerm("Spain", 1033, Guid.NewGuid());
      termEurope.CreateTerm("Germany", 1033, Guid.NewGuid());

      Term termNorthAmerica = termSet.CreateTerm("North America", 1033, Guid.NewGuid());
      termNorthAmerica.CreateTerm("Canada", 1033, Guid.NewGuid());
      termNorthAmerica.CreateTerm("United States", 1033, Guid.NewGuid());
      termNorthAmerica.CreateTerm("Mexico", 1033, Guid.NewGuid());

      clientContext.ExecuteQuery();
      termSet.TermStore.CommitAll();

    }
Ejemplo n.º 13
0
        static void CreateTerms(ClientContext clientContext, TermSet termSet)
        {
            Term termEurope = termSet.CreateTerm("Europe", 1033, Guid.NewGuid());

            termEurope.CreateTerm("United Kingdon", 1033, Guid.NewGuid());
            termEurope.CreateTerm("France", 1033, Guid.NewGuid());
            termEurope.CreateTerm("Spain", 1033, Guid.NewGuid());
            termEurope.CreateTerm("Germany", 1033, Guid.NewGuid());

            Term termNorthAmerica = termSet.CreateTerm("North America", 1033, Guid.NewGuid());

            termNorthAmerica.CreateTerm("Canada", 1033, Guid.NewGuid());
            termNorthAmerica.CreateTerm("United States", 1033, Guid.NewGuid());
            termNorthAmerica.CreateTerm("Mexico", 1033, Guid.NewGuid());

            clientContext.ExecuteQuery();
            termSet.TermStore.CommitAll();
        }
Ejemplo n.º 14
0
        protected override void ExecuteCmdlet()
        {
            var taxonomySession = TaxonomySession.GetTaxonomySession(ClientContext);
            // Get Term Store
            TermStore termStore = null;

            if (TermStore == null)
            {
                termStore = taxonomySession.GetDefaultSiteCollectionTermStore();
            }
            else
            {
                termStore = TermStore.GetTermStore(taxonomySession);
            }
            termStore.EnsureProperty(ts => ts.DefaultLanguage);

            TermGroup termGroup = TermGroup.GetGroup(termStore);

            TermSet termSet = TermSet.GetTermSet(termGroup);

            if (Id == Guid.Empty)
            {
                Id = Guid.NewGuid();
            }
            var termName = TaxonomyExtensions.NormalizeName(Name);

            if (!ParameterSpecified(nameof(Lcid)))
            {
                Lcid = termStore.EnsureProperty(ts => ts.DefaultLanguage);
            }

            var term = termSet.CreateTerm(termName, Lcid, Id);

            ClientContext.Load(term);
            ClientContext.ExecuteQueryRetry();
            term.SetDescription(Description, Lcid);

            var customProperties = CustomProperties ?? new Hashtable();

            foreach (var key in customProperties.Keys)
            {
                term.SetCustomProperty(key as string, customProperties[key] as string);
            }

            var localCustomProperties = LocalCustomProperties ?? new Hashtable();

            foreach (var key in localCustomProperties.Keys)
            {
                term.SetLocalCustomProperty(key as string, localCustomProperties[key] as string);
            }
            termStore.CommitAll();
            ClientContext.Load(term);
            ClientContext.ExecuteQueryRetry();
            WriteObject(term);
        }
Ejemplo n.º 15
0
        public void CreateTerm(TermStore termStore, string Group, string TermSetName, string termset)
        {
            // Get the term group by Name
            TermGroup termGroup = termStore.Groups.GetByName(Group);
            // Get the term set by Name
            TermSet termSet = termGroup.TermSets.GetByName(TermSetName);
            int     lcid    = 1033;
            Term    newTerm = termSet.CreateTerm(termset, lcid, Guid.NewGuid());

            Ctx.ExecuteQuery();
        }
Ejemplo n.º 16
0
        private void importTerm(TermSet set, TermData term)
        {
            var newTerm = set.CreateTerm(term.Term, 1033, Guid.NewGuid());

            foreach (var p in term.Properties)
            {
                newTerm.SetCustomProperty(p.Key, p.Value);
            }
            _ctx.Load(newTerm);
            _ctx.ExecuteQuery();
        }
Ejemplo n.º 17
0
        public static Term CreateTerm(this SPSite site, TermSet termset, string name)
        {
            if (termset.Terms.All(x => x.Name != name))
            {
                var term = termset.CreateTerm(name, int.Parse(site.RootWeb.Language.ToString()));
                term.TermStore.CommitAll();
                return term;
            }

            return termset.Terms.FirstOrDefault(x => x.Name == name);
        }
Ejemplo n.º 18
0
        public static Term AddTerm(this TermSet ts, string name, Guid guid = new Guid(), int lcid = 1033)
        {
            ts.Context.Load(ts.Terms);
            ts.Context.ExecuteQuery();
            var term = ts.Terms.FirstOrDefault(t => string.Compare(t.GetDefaultLabel(lcid).Value, name) == 0);

            if (term == null)
            {
                term = ts.CreateTerm(name, lcid, guid);
            }
            return(term);
        }
Ejemplo n.º 19
0
 private static void AddTerm(ClientContext clientContext, TermSet termSet, string termName, string termNameFrench, string termNameGerman, string termNameSwedish)
 {
     if (!termSet.Terms.Any(t => t.Name.Equals(termName)))
     {
         var term = termSet.CreateTerm(termName, 1033, Guid.NewGuid());
         term.CreateLabel(termNameGerman, 1031, false);
         term.CreateLabel(termNameFrench, 1036, false);
         term.CreateLabel(termNameSwedish, 1053, false);
         term.SetLocalCustomProperty("_Sys_Nav_SimpleLinkUrl", clientContext.Web.ServerRelativeUrl);
         clientContext.ExecuteQuery();
     }
 }
Ejemplo n.º 20
0
    private static void CreateTopLevelTerm(TermSet tset, TermInit term)
    {
        Term newTerm = tset.CreateTerm(term.TermName, 1033, term.TermID);

        if (term.ChildTerms != null)
        {
            foreach (TermInit childterm in term.ChildTerms)
            {
                CreateChildTerm(newTerm, childterm);
            }
        }
    }
Ejemplo n.º 21
0
 private static void AddTerm(ClientContext clientContext, TermSet termSet, string termName, string termNameFrench, string termNameGerman, string termNameSwedish)
 {
     if (!termSet.Terms.Any(t => t.Name.Equals(termName)))
     {
         var term = termSet.CreateTerm(termName, 1033, Guid.NewGuid());
         term.CreateLabel(termNameGerman, 1031, false);
         term.CreateLabel(termNameFrench, 1036, false);
         term.CreateLabel(termNameSwedish, 1053, false);
         term.SetLocalCustomProperty("_Sys_Nav_SimpleLinkUrl", clientContext.Web.ServerRelativeUrl);
         clientContext.ExecuteQuery();
     }
 }
Ejemplo n.º 22
0
        private static void CreateNecessaryMMSTermsToCloud(ClientContext cc)
        {
            // Get access to taxonomy CSOM
            TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(cc);

            cc.Load(taxonomySession);
            cc.ExecuteQuery();
            if (taxonomySession != null)
            {
                TermStore termStore = taxonomySession.GetDefaultSiteCollectionTermStore();
                if (termStore != null)
                {
                    //
                    //  Create group, termset, and terms.
                    //
                    TermGroup myGroup   = termStore.CreateGroup("Custom", Guid.NewGuid());
                    TermSet   myTermSet = myGroup.CreateTermSet("Colors", Guid.NewGuid(), 1033);
                    myTermSet.CreateTerm("Red", 1033, Guid.NewGuid());
                    myTermSet.CreateTerm("Orange", 1033, Guid.NewGuid());
                    myTermSet.CreateTerm("Yellow", 1033, Guid.NewGuid());
                    myTermSet.CreateTerm("Green", 1033, Guid.NewGuid());
                    myTermSet.CreateTerm("Blue", 1033, Guid.NewGuid());
                    myTermSet.CreateTerm("Purple", 1033, Guid.NewGuid());
                    cc.ExecuteQuery();
                }
            }
        }
Ejemplo n.º 23
0
        protected void createTaxonomyButton_Click(object sender, EventArgs e)
        {
            SPSite currentSite = SPContext.Current.Site;
            //To manage terms, we must create a new Taxonomy Session object
            TaxonomySession session = new TaxonomySession(currentSite);
            //Get the termstore
            TermStore termstore = session.TermStores["Managed Metadata Service"];

            //Create a term group
            Group plantsGroup = termstore.CreateGroup("Plants");

            //Create a term set
            TermSet flowersTermSet = plantsGroup.CreateTermSet("Flowers");

            //Create some terms
            Term tulipsTerm    = flowersTermSet.CreateTerm("Tulips", 1033);
            Term orchidsTerm   = flowersTermSet.CreateTerm("Orchids", 1033);
            Term daffodilsTerm = flowersTermSet.CreateTerm("Daffodils", 1033);

            //Create a child term within the Orchids term
            Term vanillaTerm = orchidsTerm.CreateTerm("Vanilla", 1033);

            //You should set properties for every term. In this example, we'll
            //do just one for brevity
            vanillaTerm.SetDescription("A common orchid whose pods are used in desserts", 1033);
            //Use CreateLabel to add synomyns and alternates
            vanillaTerm.CreateLabel("Vanilla planifolia", 1033, false);
            vanillaTerm.CreateLabel("Flat-leaved vanilla", 1033, false);

            //When we are finished making changes, we must commit them
            try
            {
                termstore.CommitAll();
                resultsLabel.Text = "Taxonomy created successfully";
            }
            catch (Exception ex)
            {
                resultsLabel.Text = "There was an error: " + ex.Message;
            }
        }
        // 4.	Crear una función para definir los términos
        static void CreateNavigationTerms(TermSet termSet)
        {
            //create terms
            Term t = termSet.CreateTerm("Home", 1033);

            t.SetLocalCustomProperty("_Sys_Nav_TargetUrl", "/Pages/default.aspx");

            t = termSet.CreateTerm("Intranet", 1033);
            t.SetLocalCustomProperty("_Sys_Nav_SimpleLinkUrl", "http://" + sphost + "/sites/publicacion/Pages/Home.aspx");

            t = termSet.CreateTerm("HR", 1033);
            t.SetLocalCustomProperty("_Sys_Nav_SimpleLinkUrl", "http://" + sphost + "/sites/publicacion/hr");

            t = termSet.CreateTerm("IT", 1033);
            t.SetLocalCustomProperty("_Sys_Nav_SimpleLinkUrl", "http://" + sphost + "/sites/publicacion/it");

            t = termSet.CreateTerm("Legal", 1033);
            t.SetLocalCustomProperty("_Sys_Nav_SimpleLinkUrl", "http://" + sphost + "/sites/publicacion/legal");

            t = termSet.CreateTerm("Finance", 1033);
            t.SetLocalCustomProperty("_Sys_Nav_SimpleLinkUrl", "http://" + sphost + "/sites/publicacion/finance");

            try
            {
                termSet.TermStore.CommitAll();
            }
            catch (Exception ex) { }
        }
Ejemplo n.º 25
0
        //gavdcodeend 05

        //gavdcodebegin 06
        static void SpCsCsomCreateTerm(ClientContext spCtx)
        {
            string termStoreName = "Taxonomy_hVIOdhme2obc+5zqZXqqUQ==";

            TaxonomySession myTaxSession = TaxonomySession.GetTaxonomySession(spCtx);
            TermStore       myTermStore  = myTaxSession.TermStores.GetByName(termStoreName);
            TermGroup       myTermGroup  = myTermStore.Groups.GetByName("CsCsomTermGroup");
            TermSet         myTermSet    = myTermGroup.TermSets.GetByName("CsCsomTermSet");

            Term myTerm = myTermSet.CreateTerm("CsCsomTerm", 1033, Guid.NewGuid());

            spCtx.ExecuteQuery();
        }
Ejemplo n.º 26
0
        public static void CriarItemNaTermStore(string url)
        {
            using (SPSite site = new SPSite(url))
            {
                TaxonomySession session = new TaxonomySession(site);

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


                Group group1 = termStore.CreateGroup("Links1");

                TermSet termSet1 = group1.CreateTermSet("TermSet1");

                Term term1 = termSet1.CreateTerm("Term1", 1033);

                Term term2 = termSet1.CreateTerm("Term2", 1033);

                Term term3 = termSet1.CreateTerm("Term3", 1033);

                Term term1a = term1.CreateTerm("Term1a", 1033);

                Term term1b = term1.CreateTerm("Term1b", 1033);

                termStore.CommitAll();

                term1.SetDescription("This is term1", 1033);

                term1.CreateLabel("TermOne", 1033, false);

                term1.CreateLabel("FirstTerm", 1033, false);

                termStore.CommitAll();


                term3.Delete();

                termStore.CommitAll();
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            TaxonomySession session      = new TaxonomySession(SPContext.Current.Site);
            TermStore       termStore    = session.TermStores[0];
            Group           myGroup      = termStore.CreateGroup("Training");
            TermSet         topicTermSet = myGroup.CreateTermSet("Topics");

            string[] topics = new string[] { "CRM", "SharePoint", "End User", "Developer", "IT Administrator", "Introduction", "Advanced" };
            foreach (string topic in topics)
            {
                Term newTerm = topicTermSet.CreateTerm(topic, 1033);
            }
            termStore.CommitAll();
        }
Ejemplo n.º 28
0
        private static void CreateTerms(TermSet termset)
        {
            var lcid = 1033;

            foreach (var term in TermInfos)
            {
                var newTerm = termset.CreateTerm(term.TermName, lcid, Guid.NewGuid());
                newTerm.SetCustomProperty("Format", term.TermFormat);

                CreateSubTerms(term, newTerm);
            }
            string[] order = SetOrder(TermInfos);
            termset.CustomSortOrder = String.Join(":", order);
        }
Ejemplo n.º 29
0
 private static void CrearTermino(ref TermStore termStore, ref TermSet termSet, string[] arbol, ref Term termResult, string cadenaAnterior, int j, int lcid)
 {
     if (j == 0)
     {
         termResult = termSet.CreateTerm(arbol[j], lcid);
         termStore.CommitAll();
     }
     else
     {
         Term termPadre = new List <Term>(termSet.GetTerms(arbol[j - 1], false, StringMatchOption.ExactMatch, 100000, false)).Find(t => t.GetPath().ToLower().Equals(cadenaAnterior.Remove(cadenaAnterior.Length - 1, 1).ToLower()));
         termResult = termPadre.CreateTerm(arbol[j], lcid);
         termStore.CommitAll();
     }
 }
Ejemplo n.º 30
0
        /// <summary>
        /// Create practice group terms
        /// </summary>
        /// <param name="TermsData">Practice group, SAOL and AOL data</param>
        /// <param name="clientContext">Client context object</param>
        private static void CreatePGTerms(List <CustomTermGroup> TermsData, ClientContext clientContext)
        {
            TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(clientContext);

            clientContext.Load(taxonomySession.TermStores);

            //Execute the query to the server
            clientContext.ExecuteQuery();
            TermStore termStore = taxonomySession.GetDefaultSiteCollectionTermStore();

            clientContext.Load(termStore.Groups);

            //Execute the query to the server
            clientContext.ExecuteQuery();

            foreach (CustomTermGroup termGroup in TermsData)
            {
                TermGroup group   = termStore.Groups.Where(groupProperties => groupProperties.Name == termGroup.name).Count() > 0 ? termStore.Groups.GetByName(termGroup.name) : termStore.CreateGroup(termGroup.name, Guid.NewGuid());
                TermSet   pracGrp = group.CreateTermSet(ConfigurationManager.AppSettings["pgterm"], Guid.NewGuid(), 1033);
                foreach (CustomPracticeGroup pg in termGroup.Pg)
                {
                    if (!string.IsNullOrWhiteSpace(pg.name))
                    {
                        Console.WriteLine("Creating practice group " + pg.name);
                        Term pgTermSet = pracGrp.CreateTerm(pg.name, 1033, Guid.NewGuid());
                        if (pg.properties.ContainsKey("PGFolders") && !string.IsNullOrWhiteSpace(pg.properties["PGFolders"]))
                        {
                            pgTermSet.SetCustomProperty("FolderNames", pg.properties["PGFolders"]);
                        }
                        foreach (CustomAreaOfLaw aol in pg.Aol)
                        {
                            if (!string.IsNullOrWhiteSpace(aol.name))
                            {
                                Console.WriteLine("\tCreating area of law " + aol.name);
                                Term AOLTerm = pgTermSet.CreateTerm(aol.name, 1033, Guid.NewGuid());
                                if (aol.properties.ContainsKey("AOLFolders") && !string.IsNullOrWhiteSpace(aol.properties["AOLFolders"]))
                                {
                                    AOLTerm.SetCustomProperty("FolderNames", aol.properties["AOLFolders"]);
                                }
                                CustomArea(aol, AOLTerm);
                            }
                        }
                    }
                }
            }
            termStore.CommitAll();
            clientContext.Load(termStore);
            //Execute the query to the server
            clientContext.ExecuteQuery();
        }
 /// <summary>
 /// An item is being added.
 /// </summary>
 public override void ItemAdding(SPItemEventProperties properties)
 {
     try
     {
         SPSecurity.RunWithElevatedPrivileges(delegate()
         {
             TaxonomySession session       = new TaxonomySession(properties.Web.Site);
             TermStore mainTermStore       = session.TermStores[0];
             Group siteGroup               = mainTermStore.GetSiteCollectionGroup(properties.Web.Site);
             TermSet issuingCompanyTermSet = GetTermSetByName("Issuing Company", siteGroup);
             if (issuingCompanyTermSet != null)
             {
                 string newTerm    = properties.AfterProperties["Title"].ToString();
                 Term matchingTerm = GetTermByName(newTerm, issuingCompanyTermSet);
                 if (matchingTerm != null)
                 {
                     if (matchingTerm.IsDeprecated)
                     {
                         matchingTerm.Deprecate(false);
                         mainTermStore.CommitAll();
                     }
                     else
                     {
                         throw new Exception(string.Format("Issuing Company with name {0} already exists.", newTerm));
                     }
                 }
                 else
                 {
                     issuingCompanyTermSet.CreateTerm(newTerm, 1033);
                     mainTermStore.CommitAll();
                 }
             }
             else
             {
                 throw new Exception("There was an error connecting to the SharePoint Managed Metadata Service");
             }
         });
     }
     catch (Exception taxonomyException)
     {
         properties.ErrorMessage = taxonomyException.Message;
         properties.Status       = SPEventReceiverStatus.CancelWithError;
     }
 }
Ejemplo n.º 32
0
        public static string AddTerm(ClientContext clientContext, TermQueryModel model)
        {
            var pickerTerm = new PickerTermModel();

            if (clientContext != null)
            {
                var taxonomySession = TaxonomySession.GetTaxonomySession(clientContext);
                var termStore       = taxonomySession.GetDefaultKeywordsTermStore();

                Term    parentTerm = null;
                TermSet termSet    = GetParent(termStore, model, out parentTerm);
                Term    newTerm    = null;
                var     newTermId  = new Guid(model.Id);
                if (parentTerm != null)
                {
                    clientContext.Load(parentTerm, t => t.PathOfTerm,
                                       t => t.Id,
                                       t => t.Labels,
                                       t => t.Name,
                                       t => t.Terms);
                    clientContext.ExecuteQuery();
                    newTerm = parentTerm.CreateTerm(model.Name, model.LCID, newTermId);
                }
                else
                {
                    clientContext.Load(termSet);
                    clientContext.ExecuteQuery();
                    newTerm = termSet.CreateTerm(model.Name, 1033, newTermId);
                }

                clientContext.Load(newTerm, t => t.PathOfTerm,
                                   t => t.Id,
                                   t => t.Labels,
                                   t => t.Name);
                clientContext.ExecuteQuery();

                pickerTerm.Name       = newTerm.Name;
                pickerTerm.Id         = newTerm.Id.ToString();
                pickerTerm.PathOfTerm = newTerm.PathOfTerm;
                pickerTerm.Level      = newTerm.PathOfTerm.Split(';').Length - 1;
                pickerTerm.Terms      = new List <PickerTermModel>();
            }
            return(JsonHelper.Serialize <PickerTermModel>(pickerTerm));
        }
Ejemplo n.º 33
0
        private static void ProcessTerms(XmlNode termSetTerms, TermSet termSet, Term currentTerm)
        {
            Term newTerm;

            foreach (XmlNode termsNames in termSetTerms.SelectNodes("Term"))
            {
                string strTermName = termsNames.Attributes["Name"].Value;
                if (currentTerm != null)
                {
                    newTerm = currentTerm.CreateTerm(strTermName, termStore.DefaultLanguage);
                }
                else
                {
                    newTerm = termSet.CreateTerm(strTermName, termStore.DefaultLanguage);
                    // termStore.CommitAll();
                }

                termStore.CommitAll();

                Console.WriteLine(strTermName);
                //ProcessLabels
                foreach (XmlNode labelNames in termsNames.SelectSingleNode("Labels").ChildNodes)
                {
                    string strLCID            = labelNames.Attributes["lcid"].Value;
                    string strLabelName       = labelNames.Attributes["Name"].Value;
                    string strTermDescription = labelNames.Attributes["Description"].Value;
                    if (Convert.ToInt32(strLCID) != termStore.DefaultLanguage)
                    {
                        newTerm.CreateLabel(strLabelName, Convert.ToInt32(strLCID), true);
                        termStore.CommitAll();
                    }
                    newTerm.SetDescription(strTermDescription, Convert.ToInt32(strLCID));
                    termStore.CommitAll();

                    Console.WriteLine(strLCID);
                    Console.WriteLine(strLabelName);
                }
                foreach (XmlNode subTerms in termsNames.SelectNodes("Terms"))
                {
                    ProcessTerms(subTerms, termSet, newTerm);
                }
            }
        }
Ejemplo n.º 34
0
        public static string GetTermIdForTerm(string term, Guid termSetId, ClientContext clientContext)
        {
            string termId = string.Empty;

            TaxonomySession tSession = TaxonomySession.GetTaxonomySession(clientContext);
            TermStore       ts       = tSession.GetDefaultSiteCollectionTermStore();
            TermSet         tset     = ts.GetTermSet(termSetId);

            LabelMatchInformation lmi = new LabelMatchInformation(clientContext);

            lmi.Lcid            = 1033;
            lmi.TrimUnavailable = true;
            lmi.TermLabel       = term;

            TermCollection termMatches = tset.GetTerms(lmi);


            //tset.CreateTerm()
            clientContext.Load(tSession);
            clientContext.Load(ts);
            clientContext.Load(tset);
            clientContext.Load(termMatches);

            clientContext.ExecuteQuery();

            if (termMatches != null && termMatches.Count() > 0)
            {
                termId = termMatches.First().Id.ToString();
            }
            else
            {
                Term TermAdd = tset.CreateTerm(term, 1033, Guid.NewGuid());
                clientContext.ExecuteQuery();
                clientContext.Load(TermAdd);
                clientContext.ExecuteQuery();
                termId = TermAdd.Id.ToString();
            }


            return(termId);
        }
Ejemplo n.º 35
0
        public static TaxonomyFieldValue GetTaxonomyFieldValue(TermSet termSet, string value, bool addIfDoesNotExist, out bool newTermAdded)
        {
            string termVal = TaxonomyItem.NormalizeName((value ?? string.Empty).Trim()); //ReplaceIllegalCharacters((value ?? string.Empty).Trim());
            Term term = null;
            newTermAdded = false;

            if (termSet != null)
            {
                if (!string.IsNullOrEmpty(termVal))
                {
                    term = termSet.GetTerms(termVal, termSet.TermStore.DefaultLanguage, true,
                                                 StringMatchOption.ExactMatch, 1, false).FirstOrDefault();
                }

                if (term == null && termSet.IsOpenForTermCreation && addIfDoesNotExist)
                {
                    if (!string.IsNullOrEmpty(termVal))
                    {
                        term = termSet.CreateTerm(termVal, termSet.TermStore.DefaultLanguage);
                        newTermAdded = true;
                        //termSet.TermStore.CommitAll();
                    }
                }

                if (term != null)
                {
                    string termValue = string.Concat(term.GetDefaultLabel(termSet.TermStore.DefaultLanguage),
                                                          TaxonomyField.TaxonomyGuidLabelDelimiter,
                                                          term.Id.ToString());
                    return TaxonomyFieldControl.GetTaxonomyValue(termValue);
                }
            }

            return null;
        }
 public static Term CreateTerm(TermSet termSet, Guid termGuid, string nameString, int LCID)
 {
     termSet.RequireNotNull("termSet");
     nameString.RequireNotNullOrEmpty("nameString");
     Term newTerm = null;
     if (!Guid.Empty.Equals(termGuid))
     {
         newTerm = termSet.CreateTerm(nameString, LCID, termGuid);
     }
     else
     {
         newTerm = termSet.CreateTerm(nameString, LCID);
     }
     return newTerm;
 }
        private void CreateStackOTerms(Stack<Tuple<string, Guid>> rowStack, TermCollection allTerms, TermSet termSet)
        {
            var arrayStack = rowStack.ToArray();
               for(int x = 0; x < arrayStack.Length; ++x)
            {
                var currentItem = arrayStack[x];
                if(currentItem.Item2 == Guid.Empty)
                {
                    var newGuid = Guid.NewGuid();
                    if (x != 0)
                    {
                        var previousTermId = arrayStack[x - 1].Item2;
                        var previousTerm = allTerms.FirstOrDefault(o=>o.Id == previousTermId);
                        //termSet.Context.Load(previousTerm);

                        if (previousTerm.IsReused && previousTerm.IsSourceTerm == false)
                        {
                            // get term
                            var sourceTerm = previousTerm.SourceTerm;
                            termSet.Context.Load(sourceTerm, sc=>sc.Id, sc => sc.Terms, sc => sc.Terms.Include(t => t.Name, t => t.Id));
                            termSet.Context.ExecuteQuery();

                            var sourceNewTerm = sourceTerm.Terms.FirstOrDefault(trm => trm.Name == currentItem.Item1);

                            // not in the original either
                            if (sourceNewTerm == null)
                            {
                                // add new term
                                var newTerm = sourceTerm.CreateTerm(currentItem.Item1, 1033, newGuid);
                                // reuse it in the term-set we are iterating
                                previousTerm.ReuseTerm(newTerm, false);
                            }
                            else{
                                previousTerm.ReuseTerm(sourceNewTerm, false);
                                newGuid = sourceNewTerm.Id;
                            }

                        }
                        else
                        {
                            previousTerm.CreateTerm(currentItem.Item1, 1033, newGuid);
                        }

                    }
                    else
                    {
                        // Create a new term at the root of the termset
                        termSet.CreateTerm(currentItem.Item1, 1033, newGuid);
                    }
                    arrayStack[x] = Tuple.Create(currentItem.Item1, newGuid);

                    allTerms = termSet.GetAllTerms();
                    termSet.Context.Load(allTerms, ax => ax.Include(t => t.Terms, t => t.PathOfTerm, t => t.IsReused, t => t.SourceTerm, t => t.IsSourceTerm, t => t.IsPinned, t => t.Name, t => t.Id, t => t.Parent, t => t.PathOfTerm, t => t.Parent.Name, t => t.Parent.Id));
                    termSet.Context.ExecuteQuery();

                }
            }
        }
        private void ProcessTermsetData(IEnumerable<string> pathData, TermSet termSet)
        {
            var allTerms = termSet.GetAllTerms();
            ts.Context.Load(allTerms, ax => ax.Include(t => t.Terms, t => t.PathOfTerm, t => t.Name, t => t.Id, t => t.Parent, t => t.PathOfTerm, t => t.Parent.Name, t => t.Parent.Id));
            ts.Context.ExecuteQuery();

            foreach (var row in pathData)
            {
                var rowCells = row.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);

                for (var cell = 0; cell < rowCells.Length; ++cell)
                {
                    // Can't find a particular term
                    var matchedTerm = allTerms.Where(o => o.Name == rowCells[cell]);
                    if (matchedTerm.Count() == 0)
                    {
                        // If we are on the first entry of arow
                        // create term at the root
                        if (cell == 0)
                        {
                            termSet.CreateTerm(rowCells[cell], 1033, Guid.NewGuid());
                            ts.Context.ExecuteQuery();
                            ts.Context.Load(allTerms);
                            ts.Context.ExecuteQuery();
                        }
                        else
                        {

                            // find the parent by the current row path.
                            // We do this because terms can appear twice if didn't areas eg Budget->2012->Docs vs Budget->2010->Docs
                            // Path is unique
                            var currentPath = String.Join(";", rowCells.Where((cel, idx) => idx < cell));
                            try
                            {

                                var parentTerm = allTerms.First(o => o.PathOfTerm == currentPath);
                                parentTerm.CreateTerm(rowCells[cell], 1033, Guid.NewGuid());
                                ts.Context.ExecuteQuery();
                                ts.Context.Load(allTerms);
                                ts.Context.ExecuteQuery();
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message + " \r\n" + ex.StackTrace);
                            }
                        }
                    }
                    termSet.TermStore.CommitAll();
                }
            }
        }
 private static void CreateTopLevelTerm(TermSet tset, TermInit term)
 {
     Term newTerm = tset.CreateTerm(term.TermName, 1033, term.TermID);
       if (term.ChildTerms != null) {
     foreach (TermInit childterm in term.ChildTerms) {
       CreateChildTerm(newTerm, childterm);
     }
       }
 }
Ejemplo n.º 40
0
        private static void ProcessTerms(XmlNode termSetTerms, TermSet termSet, Term currentTerm)
        {
            Term newTerm;

            foreach (XmlNode termsNames in termSetTerms.SelectNodes("Term"))
            {
                string strTermName = termsNames.Attributes["Name"].Value;
                if (currentTerm != null)
                {
                    newTerm = currentTerm.CreateTerm(strTermName, termStore.DefaultLanguage);
                }
                else
                {
                    newTerm = termSet.CreateTerm(strTermName, termStore.DefaultLanguage);
                    // termStore.CommitAll();
                }

                termStore.CommitAll();

                Console.WriteLine(strTermName);
                //ProcessLabels
                foreach (XmlNode labelNames in termsNames.SelectSingleNode("Labels").ChildNodes)
                {
                    string strLCID = labelNames.Attributes["lcid"].Value;
                    string strLabelName = labelNames.Attributes["Name"].Value;
                    string strTermDescription = labelNames.Attributes["Description"].Value;
                    if (Convert.ToInt32(strLCID) != termStore.DefaultLanguage)
                    {
                        newTerm.CreateLabel(strLabelName, Convert.ToInt32(strLCID), true);
                        termStore.CommitAll();
                    }
                    newTerm.SetDescription(strTermDescription, Convert.ToInt32(strLCID));
                    termStore.CommitAll();

                    Console.WriteLine(strLCID);
                    Console.WriteLine(strLabelName);
                }
                foreach (XmlNode subTerms in termsNames.SelectNodes("Terms"))
                {
                    ProcessTerms(subTerms, termSet, newTerm);
                }
            }
        }