我字段添加到列表programmaticly。下面的代碼行增加了一個新的field'to現有列表如何在SharePoint 2010中設置SPField的內部名稱?
Lists.AddFieldToList(warrantyList, SPFieldType.Text, "internalFieldName", "ShownFieldName", "Comment", false, false, false);
這是調用的方法:該方法的第一線現場充滿了很多資料後
public static bool AddFieldToList(SPList list, SPFieldType fieldType, string fieldInternalName, string fieldDisplayName, string fieldDescription, bool unique, bool required, bool indexed)
{
SPField field = new SPField(list.ParentWeb.Fields, fieldType.ToString(), fieldInternalName);
bool success = AddFieldToList(list, field, fieldDisplayName, fieldDescription, unique, required, indexed);
return success;
}
,但沒有內部名稱(NULL)和包含「internalFieldName」的標題。
在第二行下面的方法被稱爲:
public static bool AddFieldToList(SPList list, SPField field, string fieldDisplayName, string fieldDescription, bool unique, bool required, bool indexed)
{
if (field != null &&
(!list.Fields.Contains(field.Id)))
{
field.ReadOnlyField = false;
field.Title = fieldDisplayName;
field.Description = fieldDescription;
field.EnforceUniqueValues = unique;
field.Indexed = indexed;
field.Required = required;
list.Fields.Add(field);
return true;
}
return false;
}
之後的標題變爲「ShownFieldName」(當然)。但我的目標是擁有一個內部名稱「internalFieldName」,它具有DisplayName「ShownFieldName」,所以「ShownFieldName」顯示在列表中,但我可以通過內部名稱訪問該項目
as field.InternalName is readOnly:How我可以解決這個問題嗎?
感謝,馬雷克。工作。 –