public override ProvisioningTemplate CreateEntities(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo) { // if this is a sub site then we're not creating field entities. if (web.IsSubSite()) { return(template); } var existingFields = web.Fields; web.Context.Load(web, w => w.ServerRelativeUrl); web.Context.Load(existingFields, fs => fs.Include(f => f.Id, f => f.SchemaXml)); web.Context.ExecuteQueryRetry(); foreach (var field in existingFields) { if (!BuiltInFieldId.Contains(field.Id)) { var fieldXml = field.SchemaXml; XElement element = XElement.Parse(fieldXml); // Check if the field contains a reference to a list. If by Guid, rewrite the value of the attribute to use web relative paths var listIdentifier = element.Attribute("List") != null?element.Attribute("List").Value : null; if (!string.IsNullOrEmpty(listIdentifier)) { var listGuid = Guid.Empty; if (Guid.TryParse(listIdentifier, out listGuid)) { var list = web.Lists.GetById(listGuid); web.Context.Load(list, l => l.RootFolder.ServerRelativeUrl); web.Context.ExecuteQueryRetry(); var listUrl = list.RootFolder.ServerRelativeUrl.Substring(web.ServerRelativeUrl.Length).TrimStart('/'); element.Attribute("List").SetValue(listUrl); fieldXml = element.ToString(); } } // Check if we have version attribute. Remove if exists if (element.Attribute("Version") != null) { element.Attributes("Version").Remove(); fieldXml = element.ToString(); } template.SiteFields.Add(new Field() { SchemaXml = fieldXml }); } } // If a base template is specified then use that one to "cleanup" the generated template model if (creationInfo.BaseTemplate != null) { template = CleanupEntities(template, creationInfo.BaseTemplate); } return(template); }
public override ProvisioningTemplate CreateEntities(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo) { // if this is a sub site then we're not creating field entities. if (web.IsSubSite()) { return(template); } var existingFields = web.Fields; web.Context.Load(existingFields, fs => fs.Include(f => f.Id, f => f.SchemaXml)); web.Context.ExecuteQueryRetry(); foreach (var field in existingFields) { if (!BuiltInFieldId.Contains(field.Id)) { template.SiteFields.Add(new Field() { SchemaXml = field.SchemaXml }); } } // If a base template is specified then use that one to "cleanup" the generated template model if (creationInfo.BaseTemplate != null) { template = CleanupEntities(template, creationInfo.BaseTemplate); } return(template); }
public override ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo) { using (var scope = new PnPMonitoredScope(this.Name)) { // if this is a sub site then we're not creating field entities. if (web.IsSubSite()) { scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Fields_Context_web_is_subweb__skipping_site_columns); return(template); } var existingFields = web.Fields; web.Context.Load(web, w => w.ServerRelativeUrl); web.Context.Load(existingFields, fs => fs.Include(f => f.Id, f => f.SchemaXml, f => f.TypeAsString)); web.Context.ExecuteQueryRetry(); var taxTextFieldsToRemove = new List <Guid>(); foreach (var field in existingFields) { if (!BuiltInFieldId.Contains(field.Id)) { var fieldXml = field.SchemaXml; XElement element = XElement.Parse(fieldXml); // Check if the field contains a reference to a list. If by Guid, rewrite the value of the attribute to use web relative paths var listIdentifier = element.Attribute("List") != null?element.Attribute("List").Value : null; if (!string.IsNullOrEmpty(listIdentifier)) { var listGuid = Guid.Empty; if (Guid.TryParse(listIdentifier, out listGuid)) { var list = web.Lists.GetById(listGuid); web.Context.Load(list, l => l.RootFolder.ServerRelativeUrl); web.Context.ExecuteQueryRetry(); var listUrl = list.RootFolder.ServerRelativeUrl.Substring(web.ServerRelativeUrl.Length).TrimStart('/'); element.Attribute("List").SetValue(listUrl); fieldXml = element.ToString(); } } // Check if the field is of type TaxonomyField if (field.TypeAsString.StartsWith("TaxonomyField")) { var taxField = (TaxonomyField)field; web.Context.Load(taxField, tf => tf.TextField, tf => tf.Id); web.Context.ExecuteQueryRetry(); taxTextFieldsToRemove.Add(taxField.TextField); } // Check if we have version attribute. Remove if exists if (element.Attribute("Version") != null) { element.Attributes("Version").Remove(); fieldXml = element.ToString(); } template.SiteFields.Add(new Field() { SchemaXml = fieldXml }); } } // Remove hidden taxonomy text fields foreach (var textFieldId in taxTextFieldsToRemove) { template.SiteFields.RemoveAll(f => Guid.Parse(f.SchemaXml.ElementAttributeValue("ID")).Equals(textFieldId)); } // If a base template is specified then use that one to "cleanup" the generated template model if (creationInfo.BaseTemplate != null) { template = CleanupEntities(template, creationInfo.BaseTemplate); } } return(template); }
public override ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo) { using (var scope = new PnPMonitoredScope(this.Name)) { // if this is a sub site then we're not creating field entities. if (web.IsSubSite()) { scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Fields_Context_web_is_subweb__skipping_site_columns); return(template); } var existingFields = web.Fields; web.Context.Load(web, w => w.ServerRelativeUrl); web.Context.Load(existingFields, fs => fs.Include(f => f.Id, f => f.SchemaXml, f => f.TypeAsString, f => f.InternalName, f => f.Title)); web.Context.Load(web.Lists, ls => ls.Include(l => l.Id, l => l.Title)); web.Context.ExecuteQueryRetry(); var taxTextFieldsToMoveUp = new List <Guid>(); var calculatedFieldsToMoveDown = new List <Guid>(); var currentFieldIndex = 0; var fieldsToProcessCount = existingFields.Count; foreach (var field in existingFields) { currentFieldIndex++; WriteMessage($"Field|{field.InternalName}|{currentFieldIndex}|{fieldsToProcessCount}", ProvisioningMessageType.Progress); if (!BuiltInFieldId.Contains(field.Id)) { var fieldXml = field.SchemaXml; XElement element = XElement.Parse(fieldXml); // Check if the field contains a reference to a list. If by Guid, rewrite the value of the attribute to use web relative paths var listIdentifier = element.Attribute("List") != null?element.Attribute("List").Value : null; if (!string.IsNullOrEmpty(listIdentifier)) { //var listGuid = Guid.Empty; fieldXml = ParseFieldSchema(fieldXml, web.Lists); element = XElement.Parse(fieldXml); //if (Guid.TryParse(listIdentifier, out listGuid)) //{ // fieldXml = ParseListSchema(fieldXml, web.Lists); //if (newfieldXml == fieldXml) //{ // var list = web.Lists.GetById(listGuid); // web.Context.Load(list, l => l.RootFolder.ServerRelativeUrl); // web.Context.ExecuteQueryRetry(); // var listUrl = list.RootFolder.ServerRelativeUrl.Substring(web.ServerRelativeUrl.Length).TrimStart('/'); // element.Attribute("List").SetValue(listUrl); // fieldXml = element.ToString(); //} //} } // Check if the field is of type TaxonomyField if (field.TypeAsString.StartsWith("TaxonomyField")) { var taxField = (TaxonomyField)field; web.Context.Load(taxField, tf => tf.TextField, tf => tf.Id); web.Context.ExecuteQueryRetry(); taxTextFieldsToMoveUp.Add(taxField.TextField); fieldXml = TokenizeTaxonomyField(web, element); } // Check if we have version attribute. Remove if exists if (element.Attribute("Version") != null) { element.Attributes("Version").Remove(); fieldXml = element.ToString(); } if (element.Attribute("Type").Value == "Calculated") { fieldXml = TokenizeFieldFormula(web.Fields, (FieldCalculated)field, fieldXml); calculatedFieldsToMoveDown.Add(field.Id); } if (creationInfo.PersistMultiLanguageResources) { #if !SP2013 // only persist language values for fields we actually will keep...no point in spending time on this is we clean the field afterwards bool persistLanguages = true; if (creationInfo.BaseTemplate != null) { int index = creationInfo.BaseTemplate.SiteFields.FindIndex(f => Guid.Parse(XElement.Parse(f.SchemaXml).Attribute("ID").Value).Equals(field.Id)); if (index > -1) { persistLanguages = false; } } if (persistLanguages) { var fieldElement = XElement.Parse(fieldXml); var escapedFieldTitle = field.Title.Replace(" ", "_"); if (UserResourceExtensions.PersistResourceValue(field.TitleResource, $"Field_{escapedFieldTitle}_DisplayName", template, creationInfo)) { var fieldTitle = $"{{res:Field_{escapedFieldTitle}_DisplayName}}"; fieldElement.SetAttributeValue("DisplayName", fieldTitle); } if (UserResourceExtensions.PersistResourceValue(field.DescriptionResource, $"Field_{escapedFieldTitle}_Description", template, creationInfo)) { var fieldDescription = $"{{res:Field_{escapedFieldTitle}_Description}}"; fieldElement.SetAttributeValue("Description", fieldDescription); } fieldXml = fieldElement.ToString(); } #endif } template.SiteFields.Add(new Field() { SchemaXml = fieldXml }); } } // move hidden taxonomy text fields to the top of the list foreach (var textFieldId in taxTextFieldsToMoveUp) { var field = template.SiteFields.First(f => Guid.Parse(f.SchemaXml.ElementAttributeValue("ID")).Equals(textFieldId)); template.SiteFields.RemoveAll(f => Guid.Parse(f.SchemaXml.ElementAttributeValue("ID")).Equals(textFieldId)); template.SiteFields.Insert(0, field); } // move calculated fields to the bottom of the list // this will not be sufficient in the case of a calculated field is referencing another calculated field foreach (var calculatedFieldId in calculatedFieldsToMoveDown) { var field = template.SiteFields.First(f => Guid.Parse(f.SchemaXml.ElementAttributeValue("ID")).Equals(calculatedFieldId)); template.SiteFields.RemoveAll(f => Guid.Parse(f.SchemaXml.ElementAttributeValue("ID")).Equals(calculatedFieldId)); template.SiteFields.Add(field); } // If a base template is specified then use that one to "cleanup" the generated template model if (creationInfo.BaseTemplate != null) { template = CleanupEntities(template, creationInfo.BaseTemplate); } } WriteMessage($"Done processing fields", ProvisioningMessageType.Completed); return(template); }
public override ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo) { using (var scope = new PnPMonitoredScope(this.Name)) { // if this is a sub site then we're not creating field entities. if (web.IsSubSite()) { scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Fields_Context_web_is_subweb__skipping_site_columns); return(template); } var existingFields = web.Fields; web.Context.Load(web, w => w.ServerRelativeUrl); web.Context.Load(existingFields, fs => fs.Include(f => f.Id, f => f.SchemaXml, f => f.TypeAsString, f => f.InternalName, f => f.Title)); web.Context.Load(web.Lists, ls => ls.Include(l => l.Id, l => l.Title)); web.Context.ExecuteQueryRetry(); var taxTextFieldsToMoveUp = new List <Guid>(); foreach (var field in existingFields) { if (!BuiltInFieldId.Contains(field.Id)) { var fieldXml = field.SchemaXml; XElement element = XElement.Parse(fieldXml); // Check if the field contains a reference to a list. If by Guid, rewrite the value of the attribute to use web relative paths var listIdentifier = element.Attribute("List") != null?element.Attribute("List").Value : null; if (!string.IsNullOrEmpty(listIdentifier)) { var listGuid = Guid.Empty; fieldXml = ParseFieldSchema(fieldXml, web.Lists); element = XElement.Parse(fieldXml); //if (Guid.TryParse(listIdentifier, out listGuid)) //{ // fieldXml = ParseListSchema(fieldXml, web.Lists); //if (newfieldXml == fieldXml) //{ // var list = web.Lists.GetById(listGuid); // web.Context.Load(list, l => l.RootFolder.ServerRelativeUrl); // web.Context.ExecuteQueryRetry(); // var listUrl = list.RootFolder.ServerRelativeUrl.Substring(web.ServerRelativeUrl.Length).TrimStart('/'); // element.Attribute("List").SetValue(listUrl); // fieldXml = element.ToString(); //} //} } // Check if the field is of type TaxonomyField if (field.TypeAsString.StartsWith("TaxonomyField")) { var taxField = (TaxonomyField)field; web.Context.Load(taxField, tf => tf.TextField, tf => tf.Id); web.Context.ExecuteQueryRetry(); taxTextFieldsToMoveUp.Add(taxField.TextField); // Replace Taxonomy field references to SspId, TermSetId with tokens TaxonomySession session = TaxonomySession.GetTaxonomySession(web.Context); TermStore store = session.GetDefaultSiteCollectionTermStore(); var sspIdElement = element.XPathSelectElement("./Customization/ArrayOfProperty/Property[Name = 'SspId']/Value"); if (sspIdElement != null) { sspIdElement.Value = "{sitecollectiontermstoreid}"; } var termSetIdElement = element.XPathSelectElement("./Customization/ArrayOfProperty/Property[Name = 'TermSetId']/Value"); if (termSetIdElement != null) { Guid termSetId = Guid.Parse(termSetIdElement.Value); if (termSetId != Guid.Empty) { Microsoft.SharePoint.Client.Taxonomy.TermSet termSet = store.GetTermSet(termSetId); if (!termSet.ServerObjectIsNull()) { termSet.EnsureProperties(ts => ts.Name, ts => ts.Group); termSetIdElement.Value = String.Format("{{termsetid:{0}:{1}}}", termSet.Group.Name, termSet.Name); // TODO } } } } // Check if we have version attribute. Remove if exists if (element.Attribute("Version") != null) { element.Attributes("Version").Remove(); fieldXml = element.ToString(); } if (element.Attribute("Type").Value == "Calculated") { fieldXml = TokenizeFieldFormula(fieldXml); } template.SiteFields.Add(new Field() { SchemaXml = fieldXml }); } } // move hidden taxonomy text fields to the top of the list foreach (var textFieldId in taxTextFieldsToMoveUp) { var field = template.SiteFields.First(f => Guid.Parse(f.SchemaXml.ElementAttributeValue("ID")).Equals(textFieldId)); template.SiteFields.RemoveAll(f => Guid.Parse(f.SchemaXml.ElementAttributeValue("ID")).Equals(textFieldId)); template.SiteFields.Insert(0, field); } // If a base template is specified then use that one to "cleanup" the generated template model if (creationInfo.BaseTemplate != null) { template = CleanupEntities(template, creationInfo.BaseTemplate); } } return(template); }
internal override void OverrideXmlData(XElement sourceObject, XElement targetObject) { // Drop form URL properties if they're not provided in the source XML if (sourceObject.Attribute("NewFormUrl") == null) { DropAttribute(targetObject, "NewFormUrl"); } if (sourceObject.Attribute("EditFormUrl") == null) { DropAttribute(targetObject, "EditFormUrl"); } if (sourceObject.Attribute("DisplayFormUrl") == null) { DropAttribute(targetObject, "DisplayFormUrl"); } if (sourceObject.Attribute("Description") == null) { DropAttribute(targetObject, "Description"); } if (sourceObject.Attribute("Group") == null) { DropAttribute(targetObject, "Group"); } // Since we can't upload aspx files there's no point in using the engine to set a custom content type forms if (isNoScriptSite) { DropAttribute(sourceObject, "NewFormUrl"); DropAttribute(targetObject, "NewFormUrl"); DropAttribute(sourceObject, "EditFormUrl"); DropAttribute(targetObject, "EditFormUrl"); DropAttribute(sourceObject, "DisplayFormUrl"); DropAttribute(targetObject, "DisplayFormUrl"); } // Target content type is retrieved with all fieldrefs, so delete the OOB ones XNamespace ns = SchemaVersion; var fieldRefs = targetObject.Descendants(ns + "FieldRefs").FirstOrDefault(); IEnumerable <XElement> fieldRefElements = fieldRefs.Descendants(ns + "FieldRef"); List <XElement> toDelete = new List <XElement>(); foreach (var fieldRef in fieldRefElements) { // Delete the OOB fieldrefs if (BuiltInFieldId.Contains(new Guid(fieldRef.Attribute("ID").Value)) || fieldRef.Attribute("Name").Value.StartsWith("_dlc_") || fieldRef.Attribute("ID").Value.Equals("cbb92da4-fd46-4c7d-af6c-3128c2a5576e", StringComparison.InvariantCultureIgnoreCase) //DocumentSetDescription ) { toDelete.Add(fieldRef); } else { // Drop the name attribute before the comparison if (fieldRef.Attribute("Name") != null) { fieldRef.Attribute("Name").Remove(); } } } // Drop the OOB fieldrefs foreach (var fieldRef in toDelete) { fieldRef.Remove(); } // Drop empty FieldRefs element fieldRefElements = fieldRefs.Descendants(ns + "FieldRef"); if (!fieldRefElements.Any()) { fieldRefs.Remove(); } // Drop the WelcomePage attribute of the homepage if (sourceObject.Element(ns + "DocumentSetTemplate") != null) { if (sourceObject.Element(ns + "DocumentSetTemplate").Attribute("WelcomePage") != null) { sourceObject.Element(ns + "DocumentSetTemplate").Attribute("WelcomePage").Remove(); } if (isNoScriptSite) { // Setting default documents is not supported in NoScript sites so let's drop that from the comparison var defaultDocuments = sourceObject.Descendants(ns + "DefaultDocuments").FirstOrDefault(); if (defaultDocuments != null) { defaultDocuments.Remove(); } defaultDocuments = targetObject.Descendants(ns + "DefaultDocuments").FirstOrDefault(); if (defaultDocuments != null) { defaultDocuments.Remove(); } } else { // Drop the FileSourcePath attribute in both source and target var defaultDocuments = targetObject.Descendants(ns + "DefaultDocuments").FirstOrDefault(); if (defaultDocuments != null) { IEnumerable <XElement> defaultDocumentsElements = defaultDocuments.Descendants(ns + "DefaultDocument"); foreach (var defaultDocument in defaultDocumentsElements) { DropAttribute(defaultDocument, "FileSourcePath"); } } defaultDocuments = sourceObject.Descendants(ns + "DefaultDocuments").FirstOrDefault(); if (defaultDocuments != null) { IEnumerable <XElement> defaultDocumentsElements = defaultDocuments.Descendants(ns + "DefaultDocument"); foreach (var defaultDocument in defaultDocumentsElements) { DropAttribute(defaultDocument, "FileSourcePath"); } } } } }
public ProvisioningTemplate Extract(Web web, ProvisioningTemplateCreationInformation creationInfo) { ProvisioningTemplate template = new ProvisioningTemplate(); var existingFields = web.Fields; web.Context.Load(web, w => w.ServerRelativeUrl); web.Context.Load(existingFields, fs => fs.Include(f => f.Id, f => f.SchemaXml, f => f.TypeAsString, f => f.InternalName, f => f.Title)); web.Context.Load(web.Lists, ls => ls.Include(l => l.Id, l => l.Title)); web.Context.ExecuteQueryRetry(); var taxTextFieldsToMoveUp = new List <Guid>(); foreach (var field in existingFields) { if (!BuiltInFieldId.Contains(field.Id)) { var fieldXml = field.SchemaXml; var element = XElement.Parse(fieldXml); // Check if the field contains a reference to a list. If by Guid, rewrite the value of the attribute to use web relative paths var listIdentifier = element.Attribute("List") != null?element.Attribute("List").Value : null; if (!string.IsNullOrEmpty(listIdentifier)) { var listGuid = Guid.Empty; fieldXml = ParseFieldSchema(fieldXml, web.Lists); element = XElement.Parse(fieldXml); } // Check if the field is of type TaxonomyField if (field.TypeAsString.StartsWith("TaxonomyField")) { var taxField = (TaxonomyField)field; web.Context.Load(taxField, tf => tf.TextField, tf => tf.Id); web.Context.ExecuteQueryRetry(); taxTextFieldsToMoveUp.Add(taxField.TextField); fieldXml = TokenizeTaxonomyField(web, element); } // Check if we have version attribute. Remove if exists if (element.Attribute("Version") != null) { element.Attributes("Version").Remove(); fieldXml = element.ToString(); } if (element.Attribute("Type").Value == "Calculated") { fieldXml = TokenizeFieldFormula(fieldXml); } if (creationInfo.PersistMultiLanguageResources) { #if !SP2013 // only persist language values for fields we actually will keep...no point in spending time on this is we clean the field afterwards var persistLanguages = true; if (creationInfo.BaseTemplate != null) { var index = creationInfo.BaseTemplate.SiteFields.FindIndex( f => Guid.Parse(XElement.Parse(f.SchemaXml).Attribute("ID").Value).Equals(field.Id)); if (index > -1) { persistLanguages = false; } } if (persistLanguages) { var fieldElement = XElement.Parse(fieldXml); if (PersistResourceValue(field.TitleResource, string.Format("Field_{0}_DisplayName", field.Title.Replace(" ", "_")), template, creationInfo)) { var fieldTitle = string.Format("{{res:Field_{0}_DisplayName}}", field.Title.Replace(" ", "_")); fieldElement.SetAttributeValue("DisplayName", fieldTitle); } if (PersistResourceValue(field.DescriptionResource, string.Format("Field_{0}_Description", field.Title.Replace(" ", "_")), template, creationInfo)) { var fieldDescription = string.Format("{{res:Field_{0}_Description}}", field.Title.Replace(" ", "_")); fieldElement.SetAttributeValue("Description", fieldDescription); } fieldXml = fieldElement.ToString(); } #endif } template.SiteFields.Add(new PnPSiteField { SchemaXml = fieldXml }); } } // move hidden taxonomy text fields to the top of the list foreach (var textFieldId in taxTextFieldsToMoveUp) { var field = template.SiteFields.First( f => Guid.Parse(f.SchemaXml.ElementAttributeValue("ID")).Equals(textFieldId)); template.SiteFields.RemoveAll( f => Guid.Parse(f.SchemaXml.ElementAttributeValue("ID")).Equals(textFieldId)); template.SiteFields.Insert(0, field); } // If a base template is specified then use that one to "cleanup" the generated template model if (creationInfo.BaseTemplate != null) { template = CleanupEntities(template, creationInfo.BaseTemplate); } return(template); }
public override ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo) { using (var scope = new PnPMonitoredScope(this.Name)) { // if this is a sub site then we're not creating field entities. if (web.IsSubSite()) { scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Fields_Context_web_is_subweb__skipping_site_columns); return(template); } var existingFields = web.Fields; web.Context.Load(web, w => w.ServerRelativeUrl); web.Context.Load(existingFields, fs => fs.Include(f => f.Id, f => f.SchemaXml, f => f.TypeAsString, f => f.InternalName, f => f.Title)); web.Context.Load(web.Lists, ls => ls.Include(l => l.Id, l => l.Title)); web.Context.ExecuteQueryRetry(); var taxTextFieldsToMoveUp = new List <Guid>(); foreach (var field in existingFields) { if (!BuiltInFieldId.Contains(field.Id)) { var fieldXml = field.SchemaXml; XElement element = XElement.Parse(fieldXml); // Check if the field contains a reference to a list. If by Guid, rewrite the value of the attribute to use web relative paths var listIdentifier = element.Attribute("List") != null?element.Attribute("List").Value : null; if (!string.IsNullOrEmpty(listIdentifier)) { var listGuid = Guid.Empty; fieldXml = ParseFieldSchema(fieldXml, web.Lists); element = XElement.Parse(fieldXml); //if (Guid.TryParse(listIdentifier, out listGuid)) //{ // fieldXml = ParseListSchema(fieldXml, web.Lists); //if (newfieldXml == fieldXml) //{ // var list = web.Lists.GetById(listGuid); // web.Context.Load(list, l => l.RootFolder.ServerRelativeUrl); // web.Context.ExecuteQueryRetry(); // var listUrl = list.RootFolder.ServerRelativeUrl.Substring(web.ServerRelativeUrl.Length).TrimStart('/'); // element.Attribute("List").SetValue(listUrl); // fieldXml = element.ToString(); //} //} } // Check if the field is of type TaxonomyField if (field.TypeAsString.StartsWith("TaxonomyField")) { var taxField = (TaxonomyField)field; web.Context.Load(taxField, tf => tf.TextField, tf => tf.Id); web.Context.ExecuteQueryRetry(); taxTextFieldsToMoveUp.Add(taxField.TextField); fieldXml = TokenizeTaxonomyField(web, element); } // Check if we have version attribute. Remove if exists if (element.Attribute("Version") != null) { element.Attributes("Version").Remove(); fieldXml = element.ToString(); } if (element.Attribute("Type").Value == "Calculated") { fieldXml = TokenizeFieldFormula(fieldXml); } if (creationInfo.PersistMultiLanguageResources) { #if !SP2013 var fieldElement = XElement.Parse(fieldXml); if (UserResourceExtensions.PersistResourceValue(field.TitleResource, string.Format("Field_{0}_DisplayName", field.Title.Replace(" ", "_")), template, creationInfo)) { var fieldTitle = string.Format("{{res:Field_{0}_DisplayName}}", field.Title.Replace(" ", "_")); fieldElement.SetAttributeValue("DisplayName", fieldTitle); } if (UserResourceExtensions.PersistResourceValue(field.DescriptionResource, string.Format("Field_{0}_Description", field.Title.Replace(" ", "_")), template, creationInfo)) { var fieldDescription = string.Format("{{res:Field_{0}_Description}}", field.Title.Replace(" ", "_")); fieldElement.SetAttributeValue("Description", fieldDescription); } fieldXml = fieldElement.ToString(); #endif } template.SiteFields.Add(new Field() { SchemaXml = fieldXml }); } } // move hidden taxonomy text fields to the top of the list foreach (var textFieldId in taxTextFieldsToMoveUp) { var field = template.SiteFields.First(f => Guid.Parse(f.SchemaXml.ElementAttributeValue("ID")).Equals(textFieldId)); template.SiteFields.RemoveAll(f => Guid.Parse(f.SchemaXml.ElementAttributeValue("ID")).Equals(textFieldId)); template.SiteFields.Insert(0, field); } // If a base template is specified then use that one to "cleanup" the generated template model if (creationInfo.BaseTemplate != null) { template = CleanupEntities(template, creationInfo.BaseTemplate); } } return(template); }