本文整理汇总了C#中SPFieldCollection.GetFieldByInternalName方法的典型用法代码示例。如果您正苦于以下问题:C# SPFieldCollection.GetFieldByInternalName方法的具体用法?C# SPFieldCollection.GetFieldByInternalName怎么用?C# SPFieldCollection.GetFieldByInternalName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SPFieldCollection
的用法示例。
在下文中一共展示了SPFieldCollection.GetFieldByInternalName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateLookup
public SPFieldLookup CreateLookup(SPFieldCollection siteColumns, string fieldName, SPList lookupList, SPWeb web, bool required)
{
siteColumns.RequireNotNull("siteColumns");
fieldName.RequireNotNullOrEmpty("fieldName");
lookupList.RequireNotNull("lookupList");
string internalFieldName;
SPField looupField = TryGetField(siteColumns,fieldName);
if (null == looupField)
{
if (null != web)
{
internalFieldName = siteColumns.AddLookup(fieldName, lookupList.ID, web.ID, required);
}
else
{
internalFieldName = siteColumns.AddLookup(fieldName, lookupList.ID, required);
}
looupField = siteColumns.GetFieldByInternalName(internalFieldName);
}
return looupField as SPFieldLookup;
}
示例2: GetPrimaryLookupField
protected virtual SPFieldLookup GetPrimaryLookupField(SPFieldCollection fields, DependentLookupFieldDefinition definition)
{
if (definition.PrimaryLookupFieldId.HasGuidValue())
return fields[definition.PrimaryLookupFieldId.Value] as SPFieldLookup;
if (!string.IsNullOrEmpty(definition.PrimaryLookupFieldInternalName))
return fields.GetFieldByInternalName(definition.PrimaryLookupFieldInternalName) as SPFieldLookup; ;
if (!string.IsNullOrEmpty(definition.PrimaryLookupFieldTitle))
return fields.GetField(definition.PrimaryLookupFieldTitle) as SPFieldLookup; ;
throw new SPMeta2Exception("PrimaryLookupFieldTitle / PrimaryLookupFieldInternalName / PrimaryLookupFieldId need to be defined");
}
示例3: EnsureFieldFromSchema
//.........这里部分代码省略.........
// Make sure we're adding the field on a List or on a different web than the root web:
// we don't want to ensure the field twice on the root web
if (fieldCollection.List != null)
{
if (parentRootWebExistingField.EnforceUniqueValues)
{
// Before we ensure the site column on a list, gotta make sure
// that, on a list, EnforceUniqueValues=TRUE IF-AND-ONLY-IF Indexed=TRUE
parentRootWebExistingField.Indexed = true;
}
addedInternalName = fieldCollection.Add(parentRootWebExistingField);
// Then update the list column with the new list-specific or web-specfic definition
var createdField = this.fieldLocator.GetFieldById(fieldCollection, id);
createdField.SchemaXml = fieldXml.ToString(); // TODO: we should probably do a more granular update (property by property,
// only when needed) instead of brutally overwriting the schema XML like this.
createdField.Update();
}
else if (fieldCollection.Web.ID != rootWeb.ID)
{
if (!string.IsNullOrEmpty(addedInternalName))
{
// We just added the site column on the RootWeb moments ago. Adding the same field on any sub-web will
// be impossible (will trigger "Same internal name already exist" kindof error).
// This may be a bit misleading but really enforces the "always provision site columns on RootWeb" motto
this.logger.Warn("EnsureFieldFromSchema - Field was ensured on RootWeb instead of sub-web. Best practice: keep your site column definitions on the root web / avoid scattering them across your sub-webs.");
}
else
{
// User was trying to define a custom field definition on a subweb, while that site column
// is already defined on root web - which is impossible.
throw new InvalidOperationException("EnsureFieldFromSchema - Cannot ensure field on sub-web if site column already exists at root web-level. Best practive: create all your site columns on the RootWeb only.");
}
}
if (internalName != addedInternalName)
{
// Internal name changed abruptly! (probably ended up being set as DisplayName)
// This can happen when .AddFieldAsXml is used directly on a list field collection.
// Some code above tried to detect the situation and act accordingly.
// It can be surprising, when this happens: so better to have it explode violently.
throw new InvalidOperationException(
string.Format(
CultureInfo.InvariantCulture,
"Tried to add field with internal name {0}. Final field was created with internal name {1}.",
internalName,
addedInternalName));
}
this.logger.Info("End method 'EnsureField'. Added field with internal name '{0}'", addedInternalName);
}
else
{
var alreadyCreatedField = this.fieldLocator.GetFieldById(fieldCollection, id);
if (alreadyCreatedField != null && alreadyCreatedField.InternalName == internalName && alreadyCreatedField.TypeAsString == typeName)
{
// Only try updating if we managed to find the field by its ID and if
// the existing field has the same internal name (changing the internal
// name should be impossible).
alreadyCreatedField.SchemaXml = fieldXml.ToString(); // TODO: we should probably do a more granular update (property by property,
// only when needed) instead of brutally overwriting the schema XML like this.
alreadyCreatedField.Update();
this.logger.Info("End method 'EnsureField'. Field with id '{0}', display name '{1}' and internal name '{2}' was not added because it already exists in the collection.", id, displayName, internalName);
}
}
}
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);
}
// Return the newly created or the existing field
var existingField = this.fieldLocator.GetFieldById(fieldCollection, id);
if (existingField == null)
{
try
{
// Guid match failed. A field may already exist with the same internal name but a different Guid.
existingField = fieldCollection.GetFieldByInternalName(internalName);
}
catch (ArgumentException)
{
// We're probably on a sub-web's field collection, and we just sneakily created
// the site column on the RootWeb instead of on the web the user actually wanted.
existingField = fieldCollection.Web.Site.RootWeb.Fields[id];
if (existingField == null)
{
existingField = fieldCollection.Web.Site.RootWeb.Fields.GetFieldByInternalName(internalName);
}
}
}
return existingField;
}
示例4: FieldExists
private bool FieldExists(SPFieldCollection fieldCollection, string internalName, Guid fieldId)
{
if (fieldCollection.Contains(fieldId))
{
// If Id is found in the collection.
this.logger.Warn("Field with id '{0}' is already in the collection.", fieldId);
return true;
}
SPField field;
try
{
// Throws argument exception if not in collection.
field = fieldCollection.GetFieldByInternalName(internalName);
}
catch (ArgumentException)
{
return false;
}
if (field == null)
{
// Still can't find the field in the collection
return false;
}
else
{
// We found it!
this.logger.Warn("Field with display name '{0}' is already in the collection.", internalName);
return true;
}
}