protected void ConfigureTaxControls() { Microsoft.SharePoint.Taxonomy.TaxonomySession taxSession = new Microsoft.SharePoint.Taxonomy.TaxonomySession(SPContext.Current.Web.Site); Microsoft.SharePoint.Taxonomy.TermStore taxStore = taxSession.TermStores[0]; Microsoft.SharePoint.Taxonomy.Group taxGroup = GetTermStoreGroup(taxStore, ECASE_TERMS_GROUP_NAME); Microsoft.SharePoint.Taxonomy.TermSet issueTermSet = null; Microsoft.SharePoint.Taxonomy.TermSet judgeTermSet = null; //we need to attach our managed metadata UI controls to the term sets... IEnumerator <Microsoft.SharePoint.Taxonomy.TermSet> termsets = taxGroup.TermSets.GetEnumerator(); while (termsets.MoveNext()) { Microsoft.SharePoint.Taxonomy.TermSet curTermset = termsets.Current; if (curTermset.Name == ECASE_TERMS_LIL_TERMSET_NAME) { issueTermSet = curTermset; } if (curTermset.Name == ECASE_TERMS_JUDGE_TERMSET_NAME) { judgeTermSet = curTermset; } } try { //ConfigureTaxonomyControl(this.taxJudge, taxStore.Id.ToString(), taxGroup.Id, judgeTermSet.Id.ToString(), taxSession.TermStores[0].DefaultLanguage, false); ConfigureTaxonomyControl(this.lawIssue, taxStore.Id.ToString(), taxGroup.Id, issueTermSet.Id.ToString(), taxSession.TermStores[0].DefaultLanguage, false); } catch (Exception sendersEx) { } }
public void ImportTermSet(StreamReader reader, bool ignoreExistingGroup, bool isOpenForTermCreation) { Group thisGroup = GetGroup(ignoreExistingGroup); if (UseDefaultImporter) { //Get Import Manager ImportManager manager = thisGroup.TermStore.GetImportManager(); manager.ImportTermSet(thisGroup, reader, out _allTermsAdded, out _errorMessage); } else { string line; StringBuilder sb = new StringBuilder(); while (!string.IsNullOrEmpty(line = reader.ReadLine())) { if (!line.Equals(FirstLine)) { sb.AppendLine(line); } } Hashtable parsed = ParseContent(sb.ToString(), Delimiter); var entities = GetEntities(parsed).ToArray(); ImportTermSet(entities, thisGroup, isOpenForTermCreation); } }
private Group GetGroup(bool ignoreExistingGroup) { //Get TermStore Groups GroupCollection groups = _termStore.Groups; //Find group that we want to Import to Group thisGroup = groups.GetByName(_groupName); //Check that group exist if (thisGroup != null) { if (!ignoreExistingGroup) { //Get all termset from that group TermSetCollection termSets = thisGroup.TermSets; //For each termset, delete it foreach (TermSet termSet in termSets) { termSet.Delete(); } //save all changes to TermStore _termStore.CommitAll(); } } //If group doesn't exist, create it else { thisGroup = _termStore.CreateGroup(_groupName); } return(thisGroup); }
protected TermSet FindTermSet(Microsoft.SharePoint.Taxonomy.Group termGroup, TaxonomyTermSetDefinition termSetModel) { TermSet result = null; if (termSetModel.Id.HasValue) { result = termGroup.TermSets.FirstOrDefault(t => t.Id == termSetModel.Id.Value); } else if (!string.IsNullOrEmpty(termSetModel.Name)) { result = termGroup.TermSets.FirstOrDefault(t => t.Name.ToUpper() == termSetModel.Name.ToUpper()); } return(result); }
protected void ImportTermSet(IEnumerable<ManagedMetadataEntity> entities, Group termGroup, bool isOpenForTermCreation) { IEnumerable<ManagedMetadataEntity> termSetEntities = from e in entities where !string.IsNullOrEmpty(e.TermSetName) select e; // create term sets foreach (ManagedMetadataEntity termSetEntity in termSetEntities) { if (termSetEntity == null) { continue; } int lcid = termSetEntity.LCID.HasValue ? termSetEntity.LCID.Value : 1033; TermSet termSet = _termStore.GetTermSets(termSetEntity.TermSetName, lcid).FirstOrDefault(); if (termSet != null) { _termStore.WorkingLanguage = lcid; //set the working language to the language we want to add termSet.Name = termSetEntity.TermSetName; //Set the language specific name } else { termSet = termGroup.CreateTermSet(termSetEntity.TermSetName, Guid.NewGuid(), lcid); } termSet.Description = termSetEntity.TermSetDescription; termSet.IsAvailableForTagging = termSetEntity.AvailableForTagging; termSet.IsOpenForTermCreation = isOpenForTermCreation; var termLevels = new List<IEnumerable<ManagedMetadataEntity>>(); #region First Level terms Query //TODO: add logic to identify parent term set.. and modify spreadsheet appropriately... IEnumerable<ManagedMetadataEntity> firstLevelTerms = from e in entities where (!String.IsNullOrEmpty(e.Level1Term) && String.IsNullOrEmpty(e.Level2Term) && String.IsNullOrEmpty(e.Level3Term) && String.IsNullOrEmpty(e.Level4Term) && String.IsNullOrEmpty(e.Level5Term) && string.IsNullOrEmpty(e.Level6Term) && String.IsNullOrEmpty(e.Level7Term) && e.LCID == termSetEntity.LCID) select e; termLevels.Add(firstLevelTerms); #endregion //Set custom order to match import //termSet.CustomSortOrder = String.Join(":", firstLevelTerms.Select(x => x.Level1Term).ToArray()); _termStore.CommitAll(); #region Second Level Terms Query var secondLevelTerms = from e in entities where (!String.IsNullOrEmpty(e.Level1Term) && !String.IsNullOrEmpty(e.Level2Term) && String.IsNullOrEmpty(e.Level3Term) && String.IsNullOrEmpty(e.Level4Term) && String.IsNullOrEmpty(e.Level5Term) && string.IsNullOrEmpty(e.Level6Term) && String.IsNullOrEmpty(e.Level7Term) && e.LCID == termSetEntity.LCID) select e; termLevels.Add(secondLevelTerms); #endregion #region Third Level Terms Query var thirdLevelTerms = from e in entities where (!String.IsNullOrEmpty(e.Level1Term) && !String.IsNullOrEmpty(e.Level2Term) && !String.IsNullOrEmpty(e.Level3Term) && String.IsNullOrEmpty(e.Level4Term) && String.IsNullOrEmpty(e.Level5Term) && string.IsNullOrEmpty(e.Level6Term) && String.IsNullOrEmpty(e.Level7Term) && e.LCID == termSetEntity.LCID) select e; termLevels.Add(thirdLevelTerms); #endregion #region Fourth Level Terms Query var fourthLevelTerms = from e in entities where (!String.IsNullOrEmpty(e.Level1Term) && !String.IsNullOrEmpty(e.Level2Term) && !String.IsNullOrEmpty(e.Level3Term) && !String.IsNullOrEmpty(e.Level4Term) && String.IsNullOrEmpty(e.Level5Term) && String.IsNullOrEmpty(e.Level6Term) && String.IsNullOrEmpty(e.Level7Term) && e.LCID == termSetEntity.LCID) select e; termLevels.Add(fourthLevelTerms); #endregion #region Fifth Level Terms Query var fifthLevelTerms = from e in entities where (!String.IsNullOrEmpty(e.Level1Term) && !String.IsNullOrEmpty(e.Level2Term) && !String.IsNullOrEmpty(e.Level3Term) && !String.IsNullOrEmpty(e.Level4Term) && !String.IsNullOrEmpty(e.Level5Term) && String.IsNullOrEmpty(e.Level6Term) && String.IsNullOrEmpty(e.Level7Term) && e.LCID == termSetEntity.LCID) select e; termLevels.Add(fifthLevelTerms); #endregion #region Sixth Level Terms Query var sixthLevelTerms = from e in entities where (!String.IsNullOrEmpty(e.Level1Term) && !String.IsNullOrEmpty(e.Level2Term) && !String.IsNullOrEmpty(e.Level3Term) && !String.IsNullOrEmpty(e.Level4Term) && !String.IsNullOrEmpty(e.Level5Term) && !String.IsNullOrEmpty(e.Level6Term) && String.IsNullOrEmpty(e.Level7Term) && e.LCID == termSetEntity.LCID) select e; termLevels.Add(sixthLevelTerms); #endregion #region Seventh Level Terms Query IEnumerable<ManagedMetadataEntity> seventhLevelTerms = from e in entities where (!String.IsNullOrEmpty(e.Level1Term) && !String.IsNullOrEmpty(e.Level2Term) && !String.IsNullOrEmpty(e.Level3Term) && !String.IsNullOrEmpty(e.Level4Term) && !String.IsNullOrEmpty(e.Level5Term) && !String.IsNullOrEmpty(e.Level6Term) && !String.IsNullOrEmpty(e.Level7Term) && e.LCID == termSetEntity.LCID) select e; termLevels.Add(seventhLevelTerms); #endregion foreach (ManagedMetadataEntity termEntity in firstLevelTerms) { UpdateTerm(termSet, termEntity, termLevels, 1); } _termStore.CommitAll(); } }
protected void btnSearch_Click(object sender, EventArgs e) { string validationReason; //if (taxJudge.Validate(out validationReason) && taxIssue.Validate(out validationReason) && taxJudge.Text != string.Empty && taxIssue.Text != string.Empty) if (lawIssue.Validate(out validationReason) && lawIssue.Text != string.Empty) { Microsoft.SharePoint.Taxonomy.TaxonomySession taxSession = new Microsoft.SharePoint.Taxonomy.TaxonomySession(SPContext.Current.Web.Site); Microsoft.SharePoint.Taxonomy.TermStore taxStore = taxSession.TermStores[0]; Microsoft.SharePoint.Taxonomy.Group taxGroup = GetTermStoreGroup(taxStore, ECASE_TERMS_GROUP_NAME); Microsoft.SharePoint.Taxonomy.TermSet issueTermSet = null; Microsoft.SharePoint.Taxonomy.TermSet judgeTermSet = null; //we need to attach our managed metadata UI controls to the term sets... IEnumerator <Microsoft.SharePoint.Taxonomy.TermSet> termsets = taxGroup.TermSets.GetEnumerator(); while (termsets.MoveNext()) { Microsoft.SharePoint.Taxonomy.TermSet curTermset = termsets.Current; if (curTermset.Name == ECASE_TERMS_LIL_TERMSET_NAME) { issueTermSet = curTermset; } if (curTermset.Name == ECASE_TERMS_JUDGE_TERMSET_NAME) { judgeTermSet = curTermset; } } pnlResults.Visible = true; //Guid judgeTermId = new Guid(taxJudge.Text.Split('|')[1]); //int[] judgeIntCollection = TaxonomyField.GetWssIdsOfTerm(SPContext.Current.Web.Site, taxStore.Id, // judgeTermSet.Id, judgeTermId, false, 50); Guid issueTermId = new Guid(lawIssue.Text.Split('|')[1]); int[] issueIntCollection = TaxonomyField.GetWssIdsOfTerm(SPContext.Current.Web.Site, taxStore.Id, issueTermSet.Id, issueTermId, false, 50); //String CAML_QUERY = // @"<Where><And><In><FieldRef LookupId=""True"" Name=""Judge"" /><Values>{0}</Values></In><In><FieldRef LookupId=""True"" Name=""UniformIssueList"" /><Values>{1}</Values></In></And></Where>"; //String VALUES = @"<Value Type=""Integer"">{0}</Value>"; String CAML_QUERY = @"<Where><In><FieldRef LookupId=""True"" Name=""LawIssueList"" /><Values>{0}</Values></In></Where>"; String VALUES = @"<Value Type=""Integer"">{0}</Value>"; //StringBuilder strJudgeValues = new StringBuilder(); StringBuilder strIssueValues = new StringBuilder(); //foreach (int judgeInt in judgeIntCollection) //{ // strJudgeValues.AppendLine(String.Format(VALUES, judgeInt)); //} foreach (int issueInt in issueIntCollection) { strIssueValues.AppendLine(String.Format(VALUES, issueInt)); } //String strQuery = String.Format(CAML_QUERY, strJudgeValues.ToString(), strIssueValues.ToString()); String strQuery = String.Format(CAML_QUERY, strIssueValues.ToString()); litIssue.Text = lawIssue.Text.Split('|')[0]; //litJudge.Text = taxJudge.Text.Split('|')[0]; //if (strIssueValues.Length == 0 || strJudgeValues.Length == 0) if (strIssueValues.Length == 0) { litOwners.Text = "<b>There are no results</b>"; } else { SPQuery sPQuery = new SPQuery(); sPQuery.Query = strQuery; SPListItemCollection results = null; SPSecurity.RunWithElevatedPrivileges(delegate() { using ( SPSite site = new SPSite(SPContext.Current.Web.Site.ID)) { SPWeb web = site.RootWeb; SPList casesList = web.Lists["Cases"]; results = casesList.GetItems(sPQuery); } }); litOwners.Text = string.Empty; foreach (SPListItem result in results) { litOwners.Text += new SPFieldLookupValue(result["AssignedTo"].ToString()).LookupValue + "<br />"; } if (litOwners.Text == string.Empty) { litOwners.Text = "<b>There are no results</b>"; } } } else { pnlResults.Visible = true; litOwners.Text = "<b>The data entered in the Law Issues List fields is invalid. Please ensure the field contains valid values.</b>"; } }
protected void ImportTermSet(IEnumerable <ManagedMetadataEntity> entities, Group termGroup, bool isOpenForTermCreation) { IEnumerable <ManagedMetadataEntity> termSetEntities = from e in entities where !string.IsNullOrEmpty(e.TermSetName) select e; // create term sets foreach (ManagedMetadataEntity termSetEntity in termSetEntities) { if (termSetEntity == null) { continue; } int lcid = termSetEntity.LCID.HasValue ? termSetEntity.LCID.Value : 1033; TermSet termSet = _termStore.GetTermSets(termSetEntity.TermSetName, lcid).FirstOrDefault(); if (termSet != null) { _termStore.WorkingLanguage = lcid; //set the working language to the language we want to add termSet.Name = termSetEntity.TermSetName; //Set the language specific name } else { termSet = termGroup.CreateTermSet(termSetEntity.TermSetName, Guid.NewGuid(), lcid); } termSet.Description = termSetEntity.TermSetDescription; termSet.IsAvailableForTagging = termSetEntity.AvailableForTagging; termSet.IsOpenForTermCreation = isOpenForTermCreation; var termLevels = new List <IEnumerable <ManagedMetadataEntity> >(); #region First Level terms Query //TODO: add logic to identify parent term set.. and modify spreadsheet appropriately... IEnumerable <ManagedMetadataEntity> firstLevelTerms = from e in entities where (!String.IsNullOrEmpty(e.Level1Term) && String.IsNullOrEmpty(e.Level2Term) && String.IsNullOrEmpty(e.Level3Term) && String.IsNullOrEmpty(e.Level4Term) && String.IsNullOrEmpty(e.Level5Term) && string.IsNullOrEmpty(e.Level6Term) && String.IsNullOrEmpty(e.Level7Term) && e.LCID == termSetEntity.LCID) select e; termLevels.Add(firstLevelTerms); #endregion //Set custom order to match import //termSet.CustomSortOrder = String.Join(":", firstLevelTerms.Select(x => x.Level1Term).ToArray()); _termStore.CommitAll(); #region Second Level Terms Query var secondLevelTerms = from e in entities where (!String.IsNullOrEmpty(e.Level1Term) && !String.IsNullOrEmpty(e.Level2Term) && String.IsNullOrEmpty(e.Level3Term) && String.IsNullOrEmpty(e.Level4Term) && String.IsNullOrEmpty(e.Level5Term) && string.IsNullOrEmpty(e.Level6Term) && String.IsNullOrEmpty(e.Level7Term) && e.LCID == termSetEntity.LCID) select e; termLevels.Add(secondLevelTerms); #endregion #region Third Level Terms Query var thirdLevelTerms = from e in entities where (!String.IsNullOrEmpty(e.Level1Term) && !String.IsNullOrEmpty(e.Level2Term) && !String.IsNullOrEmpty(e.Level3Term) && String.IsNullOrEmpty(e.Level4Term) && String.IsNullOrEmpty(e.Level5Term) && string.IsNullOrEmpty(e.Level6Term) && String.IsNullOrEmpty(e.Level7Term) && e.LCID == termSetEntity.LCID) select e; termLevels.Add(thirdLevelTerms); #endregion #region Fourth Level Terms Query var fourthLevelTerms = from e in entities where (!String.IsNullOrEmpty(e.Level1Term) && !String.IsNullOrEmpty(e.Level2Term) && !String.IsNullOrEmpty(e.Level3Term) && !String.IsNullOrEmpty(e.Level4Term) && String.IsNullOrEmpty(e.Level5Term) && String.IsNullOrEmpty(e.Level6Term) && String.IsNullOrEmpty(e.Level7Term) && e.LCID == termSetEntity.LCID) select e; termLevels.Add(fourthLevelTerms); #endregion #region Fifth Level Terms Query var fifthLevelTerms = from e in entities where (!String.IsNullOrEmpty(e.Level1Term) && !String.IsNullOrEmpty(e.Level2Term) && !String.IsNullOrEmpty(e.Level3Term) && !String.IsNullOrEmpty(e.Level4Term) && !String.IsNullOrEmpty(e.Level5Term) && String.IsNullOrEmpty(e.Level6Term) && String.IsNullOrEmpty(e.Level7Term) && e.LCID == termSetEntity.LCID) select e; termLevels.Add(fifthLevelTerms); #endregion #region Sixth Level Terms Query var sixthLevelTerms = from e in entities where (!String.IsNullOrEmpty(e.Level1Term) && !String.IsNullOrEmpty(e.Level2Term) && !String.IsNullOrEmpty(e.Level3Term) && !String.IsNullOrEmpty(e.Level4Term) && !String.IsNullOrEmpty(e.Level5Term) && !String.IsNullOrEmpty(e.Level6Term) && String.IsNullOrEmpty(e.Level7Term) && e.LCID == termSetEntity.LCID) select e; termLevels.Add(sixthLevelTerms); #endregion #region Seventh Level Terms Query IEnumerable <ManagedMetadataEntity> seventhLevelTerms = from e in entities where (!String.IsNullOrEmpty(e.Level1Term) && !String.IsNullOrEmpty(e.Level2Term) && !String.IsNullOrEmpty(e.Level3Term) && !String.IsNullOrEmpty(e.Level4Term) && !String.IsNullOrEmpty(e.Level5Term) && !String.IsNullOrEmpty(e.Level6Term) && !String.IsNullOrEmpty(e.Level7Term) && e.LCID == termSetEntity.LCID) select e; termLevels.Add(seventhLevelTerms); #endregion foreach (ManagedMetadataEntity termEntity in firstLevelTerms) { UpdateTerm(termSet, termEntity, termLevels, 1); } _termStore.CommitAll(); } }