本文整理汇总了C#中FieldCollection.AddFieldAsXml方法的典型用法代码示例。如果您正苦于以下问题:C# FieldCollection.AddFieldAsXml方法的具体用法?C# FieldCollection.AddFieldAsXml怎么用?C# FieldCollection.AddFieldAsXml使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FieldCollection
的用法示例。
在下文中一共展示了FieldCollection.AddFieldAsXml方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EnsureField
private Field EnsureField(ClientRuntimeContext context, Field currentField, FieldCollection fieldCollection,
FieldDefinition fieldModel)
{
TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "EnsureField()");
if (currentField == null)
{
TraceService.Verbose((int)LogEventId.ModelProvisionProcessingNewObject, "Current field is NULL. Creating new");
var fieldDef = GetTargetSPFieldXmlDefinition(fieldModel);
var addFieldOptions = (AddFieldOptions)(int)fieldModel.AddFieldOptions;
var resultField = fieldCollection.AddFieldAsXml(fieldDef, fieldModel.AddToDefaultView, addFieldOptions);
if (PreloadProperties(resultField))
{
context.ExecuteQueryWithTrace();
}
ProcessFieldProperties(resultField, fieldModel);
return resultField;
}
else
{
TraceService.Verbose((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing field");
ProcessFieldProperties(currentField, fieldModel);
return currentField;
}
}
示例2: EnsureField
private Field EnsureField(ClientRuntimeContext context, FieldCollection fieldCollection, FieldDefinition fieldModel)
{
var currentField = FindExistingField(fieldCollection, fieldModel.InternalName);
if (currentField == null)
{
var fieldDef = string.Format(SiteFieldXmlTemplate,
new string[]
{
fieldModel.Id.ToString("B"),
fieldModel.InternalName,
fieldModel.Title,
fieldModel.Title,
fieldModel.InternalName,
fieldModel.FieldType,
fieldModel.Group
});
currentField = fieldCollection.AddFieldAsXml(fieldDef, false, AddFieldOptions.DefaultValue);
}
currentField.Title = fieldModel.Title;
currentField.Description = fieldModel.Description ?? string.Empty;
currentField.Group = fieldModel.Group ?? string.Empty;
return currentField;
}
示例3: CreateField
private void CreateField(ShField field, FieldCollection fields)
{
// code to handle lookup fields. does not work if the list has not been created...
if (field.Type == "Lookup" || field.Type == "LookupMulti")
{
var web = ClientContext.Web;
if (!web.IsObjectPropertyInstantiated("Lists"))
{
ClientContext.Load(web, x => x.Lists);
ClientContext.ExecuteQuery();
}
var listTitle = field.List;
var list = web.Lists.GetByTitle(listTitle);
try
{
ClientContext.Load(list, x=>x.Id);
ClientContext.ExecuteQuery();
field.List = list.Id.ToString();
}
catch (Exception)
{
Log.Info("Lookup field " + field.DisplayName + " id:" + field.ID + " cannot be created since the list " + listTitle + " has not been created. Please rund content type creation again after setting up the site hierarchy");
return;
}
}
var fieldXml = field.GetFieldAsXml();
Field newField = fields.AddFieldAsXml(fieldXml, true, AddFieldOptions.AddFieldInternalNameHint);
ClientContext.Load(newField);
ClientContext.ExecuteQuery();
}
示例4: CreateTaxonomyField
private void CreateTaxonomyField(ShField field, FieldCollection fields)
{
Log.Debug("Attempting to create taxonomy field " + field.DisplayName);
var fieldSchema = field.GetFieldAsXml();
var newField = fields.AddFieldAsXml(fieldSchema, false, AddFieldOptions.AddFieldInternalNameHint);
ClientContext.Load(newField);
ClientContext.ExecuteQuery();
var termSetId = GetTermSetId(field);
var newTaxonomyField = ClientContext.CastTo<TaxonomyField>(newField);
newTaxonomyField.SspId = field.SspId;
newTaxonomyField.TermSetId = termSetId;
newTaxonomyField.TargetTemplate = String.Empty;
newTaxonomyField.AnchorId = Guid.Empty;
newTaxonomyField.CreateValuesInEditForm = field.OpenTermSet;
newTaxonomyField.Open = field.OpenTermSet;
newTaxonomyField.Update();
ClientContext.ExecuteQuery();
}
示例5: EnsureField
private Field EnsureField(ClientRuntimeContext context, Field currentField, FieldCollection fieldCollection,
FieldDefinition fieldModel)
{
TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "EnsureField()");
if (currentField == null)
{
TraceService.Verbose((int)LogEventId.ModelProvisionProcessingNewObject, "Current field is NULL. Creating new");
var fieldDef = GetTargetSPFieldXmlDefinition(fieldModel);
// special handle for taxonomy field
// incorectly removed tax field leaves its indexed field
// https://github.com/SubPointSolutions/spmeta2/issues/521
HandleIncorectlyDeletedTaxonomyField(fieldModel, fieldCollection);
var addFieldOptions = (AddFieldOptions)(int)fieldModel.AddFieldOptions;
var resultField = fieldCollection.AddFieldAsXml(fieldDef, fieldModel.AddToDefaultView, addFieldOptions);
ProcessFieldProperties(resultField, fieldModel);
return resultField;
}
else
{
TraceService.Verbose((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing field");
ProcessFieldProperties(currentField, fieldModel);
return currentField;
}
}