示例#1
0
        public void CreateFields()
        {
            Web web = ClientContext.Web;
            FieldCollection webFieldCollection = web.Fields;
            ClientContext.Load(webFieldCollection);
            ClientContext.ExecuteQuery();

            var termStoreId = new TaxonomyManager(null).GetTermStoreId(ClientContext);
            foreach (ShField field in Fields)
            {
                var existingField = webFieldCollection.SingleOrDefault(item => item.InternalName == field.InternalName);
                if (existingField == null)
                {
                    //Creating new field
                    Log.Debug("Attempting to create field " + field.DisplayName);
                    if (field.Type.StartsWith("TaxonomyFieldType"))
                    {
                        field.SspId = termStoreId;
                        DeleteHiddenFieldForTaxonomyField(webFieldCollection, field.ID);
                        CreateTaxonomyField(field, webFieldCollection);
                    }
                    else
                    {
                        CreateField(field, webFieldCollection);
                    }
                }
                else
                {
                    //Updating existing field
                    UpdateExistingField(field, existingField);
                }
            }
        }
示例#2
0
 private void InstallTaxonomyFromSingleFile(ClientContext context, string pathToFile)
 {
     Log.Info("Starting installation of taxonomy based on " + pathToFile);
     var taxPersistanceProvider = new FilePersistanceProvider<ShTermGroup>(pathToFile);
     var taxonomyManager = new TaxonomyManager(taxPersistanceProvider.Load());
     taxonomyManager.WriteTaxonomyToTermStore(context);
 }
示例#3
0
 private void ExportTaxonomyGroup(string groupName)
 {
     Log.Info("Starting export of taxonomy group " + groupName);
     using (var context = new ClientContext(_urlToSite))
     {
         context.Credentials = _credentials;
         var outputDirectoryPath = Path.Combine(_rootPath, "export");
         Directory.CreateDirectory(outputDirectoryPath);
         var taxPersistanceProvider = new FilePersistanceProvider<ShTermGroup>(Path.Combine(outputDirectoryPath, groupName.ToLower().Replace(" ", "") + "taxonomy.json"));
         var taxonomyManager = new TaxonomyManager();
         var groupConfig = taxonomyManager.ExportTaxonomyGroupToConfig(context, groupName);
         if (groupConfig != null)
         {
             taxPersistanceProvider.Save(groupConfig);
             Log.Info("Completed export of taxonomy group " + groupName);
         }
     }
 }
示例#4
0
        private Guid GetTermSetId(ShField field)
        {
            if (field.TermSetId != Guid.Empty) return field.TermSetId;

            if (string.IsNullOrEmpty(field.TermSetName))
            {
                throw new Exception("Invalid taxonomy configuration settings for field " + field.DisplayName);
            }
            var manager = new TaxonomyManager();
            return manager.GetTermSetId(ClientContext, field.TermSetName);
        }