本文整理汇总了C#中SPFieldCollection.AddFieldAsXml方法的典型用法代码示例。如果您正苦于以下问题:C# SPFieldCollection.AddFieldAsXml方法的具体用法?C# SPFieldCollection.AddFieldAsXml怎么用?C# SPFieldCollection.AddFieldAsXml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SPFieldCollection
的用法示例。
在下文中一共展示了SPFieldCollection.AddFieldAsXml方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddField
/// <summary>
/// Adds a field defined in xml to a collection of fields.
/// </summary>
/// <param name="fieldCollection">The SPField collection.</param>
/// <param name="fieldXml">The field XML schema.</param>
/// <returns>
/// A string that contains the internal name of the new field.
/// </returns>
/// <exception cref="System.ArgumentNullException">
/// fieldCollection
/// or
/// fieldXml
/// </exception>
/// <exception cref="System.FormatException">Invalid xml.</exception>
public string AddField(SPFieldCollection fieldCollection, XElement fieldXml)
{
if (fieldCollection == null)
{
throw new ArgumentNullException("fieldCollection");
}
if (fieldXml == null)
{
throw new ArgumentNullException("fieldXml");
}
this._logger.Info("Start method 'AddField'");
Guid id = Guid.Empty;
string displayName = string.Empty;
string internalName = string.Empty;
// Validate the xml of the field and get its
if (this.IsFieldXmlValid(fieldXml, out id, out displayName, out internalName))
{
// Check if the field already exists. Skip the creation if so.
if (!this.FieldExists(fieldCollection, displayName, id))
{
// If its a lookup we need to fix up the xml.
if (this.IsLookup(fieldXml))
{
fieldXml = this.FixLookupFieldXml(fieldCollection.Web, fieldXml);
}
string addedInternalName = fieldCollection.AddFieldAsXml(fieldXml.ToString(), false, SPAddFieldOptions.Default);
this._logger.Info("End method 'AddField'. Added field with internal name '{0}'", addedInternalName);
return addedInternalName;
}
else
{
this._logger.Warn("End method 'AddField'. Field with id '{0}' and display name '{1}' was not added because it already exists in the collection.", id, displayName);
return string.Empty;
}
}
else
{
string msg = string.Format(CultureInfo.InvariantCulture, "Unable to create field. Invalid xml. id: '{0}' DisplayName: '{1}' Name: '{2}'", id, displayName, internalName);
throw new FormatException(msg);
}
}
示例2: EnsureFieldInFieldsCollection
private SPField EnsureFieldInFieldsCollection(
object modelHost,
SPFieldCollection fields, FieldDefinition fieldModel)
{
var currentField = fields.OfType<SPField>()
.FirstOrDefault(f => f.Id == fieldModel.Id);
if (currentField == null)
{
TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new field");
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioning,
Object = currentField,
ObjectType = GetTargetFieldType(fieldModel),
ObjectDefinition = fieldModel,
ModelHost = modelHost
});
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, fields);
var addFieldOptions = (SPAddFieldOptions)(int)fieldModel.AddFieldOptions;
fields.AddFieldAsXml(fieldDef, fieldModel.AddToDefaultView, addFieldOptions);
currentField = fields[fieldModel.Id];
}
else
{
TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing field");
currentField = fields[fieldModel.Id];
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioning,
Object = currentField,
ObjectType = GetTargetFieldType(fieldModel),
ObjectDefinition = fieldModel,
ModelHost = modelHost
});
}
return currentField;
}
示例3: EnsureFieldInFieldsCollection
private SPField EnsureFieldInFieldsCollection(
object modelHost,
SPFieldCollection fields, FieldDefinition fieldModel)
{
var currentField = fields.OfType<SPField>()
.FirstOrDefault(f => f.Id == fieldModel.Id);
if (currentField == null)
{
TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new field");
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioning,
Object = currentField,
ObjectType = GetTargetFieldType(fieldModel),
ObjectDefinition = fieldModel,
ModelHost = modelHost
});
var fieldDef = GetTargetSPFieldXmlDefinition(fieldModel);
var addFieldOptions = (SPAddFieldOptions)(int)fieldModel.AddFieldOptions;
fields.AddFieldAsXml(fieldDef, fieldModel.AddToDefaultView, addFieldOptions);
currentField = fields[fieldModel.Id];
}
else
{
TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing field");
currentField = fields[fieldModel.Id];
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioning,
Object = currentField,
ObjectType = GetTargetFieldType(fieldModel),
ObjectDefinition = fieldModel,
ModelHost = modelHost
});
}
return currentField;
}
示例4: EnsureFieldInFieldsCollection
private SPField EnsureFieldInFieldsCollection(
object modelHost,
SPFieldCollection fields, FieldDefinition fieldModel)
{
// by ID?
var currentField = fields.OfType<SPField>()
.FirstOrDefault(f => f.Id == fieldModel.Id);
// by internal name?
if (currentField == null && !string.IsNullOrEmpty(fieldModel.InternalName))
{
TraceService.Information((int)LogEventId.CoreCalls, "Could not find field by ID, fallback on InternalName");
currentField = fields.OfType<SPField>()
.FirstOrDefault(f => String.Equals(f.InternalName, fieldModel.InternalName,
StringComparison.OrdinalIgnoreCase));
}
if (currentField == null)
{
TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new field");
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioning,
Object = currentField,
ObjectType = GetTargetFieldType(fieldModel),
ObjectDefinition = fieldModel,
ModelHost = modelHost
});
var fieldDef = GetTargetSPFieldXmlDefinition(fieldModel);
var addFieldOptions = (SPAddFieldOptions)(int)fieldModel.AddFieldOptions;
fields.AddFieldAsXml(fieldDef, fieldModel.AddToDefaultView, addFieldOptions);
currentField = fields[fieldModel.Id];
}
else
{
TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing field");
currentField = fields.OfType<SPField>()
.FirstOrDefault(f => f.Id == fieldModel.Id);
if (currentField == null && !string.IsNullOrEmpty(fieldModel.InternalName))
{
TraceService.Information((int)LogEventId.CoreCalls, "Could not find existing field by ID, fallback on InternalName");
currentField = fields.OfType<SPField>()
.FirstOrDefault(f => String.Equals(f.InternalName, fieldModel.InternalName,
StringComparison.OrdinalIgnoreCase));
}
if (currentField == null)
{
throw new SPMeta2Exception(
string.Format("Cannot find existing field neither by ID [{0}] or InternalName [{1}]. Definition:[{2}]",
fieldModel.Id, fieldModel.InternalName, fieldModel));
}
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioning,
Object = currentField,
ObjectType = GetTargetFieldType(fieldModel),
ObjectDefinition = fieldModel,
ModelHost = modelHost
});
}
return currentField;
}
示例5: EnsureFieldInFieldsCollection
private SPField EnsureFieldInFieldsCollection(
object modelHost,
SPFieldCollection fields, FieldDefinition fieldModel)
{
SPField currentField = null;
if (!fields.ContainsFieldWithStaticName(fieldModel.InternalName))
{
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioning,
Object = currentField,
ObjectType = typeof(SPField),
ObjectDefinition = fieldModel,
ModelHost = modelHost
});
// first creation
var fieldDef = string.Format(MinimalSPFieldTemplate, new string[]
{
fieldModel.Id.ToString("B"),
fieldModel.InternalName,
fieldModel.Title,
fieldModel.Title,
fieldModel.InternalName,
fieldModel.FieldType
});
fields.AddFieldAsXml(fieldDef);
currentField = fields[fieldModel.Id];
}
else
{
currentField = fields[fieldModel.Id];
InvokeOnModelEvent(this, new ModelEventArgs
{
CurrentModelNode = null,
Model = null,
EventType = ModelEventType.OnProvisioning,
Object = currentField,
ObjectType = typeof(SPField),
ObjectDefinition = fieldModel,
ModelHost = modelHost
});
}
return currentField;
}
示例6: CreateField
public virtual string CreateField(SPFieldCollection fieldCollection, XmlNode schemaXml, bool addToDefaultView, SPAddFieldOptions options)
{
return fieldCollection.AddFieldAsXml(schemaXml.OuterXml, addToDefaultView, options);
}