Tôi thêm các trường vào danh sách theo chương trình. Dòng sau đây thêm một field'to mới một danh sách hiện cóLàm cách nào để đặt tên nội bộ cho SPField trong SharePoint 2010?
Lists.AddFieldToList(warrantyList, SPFieldType.Text, "internalFieldName", "ShownFieldName", "Comment", false, false, false);
Đây là phương pháp được gọi là:
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;
}
sau khi dòng đầu tiên của phương pháp lĩnh vực này được làm đầy với rất nhiều thông tin , nhưng không có internalName (NULL) và một Tiêu đề có chứa "internalFieldName".
Trong dòng thứ hai phương pháp sau đây được gọi là:
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;
}
Sau đó danh hiệu được đổi thành "ShownFieldName" (tất nhiên). Nhưng mục tiêu của tôi là có tên nội bộ là "internalFieldName" có tên hiển thị là "ShownFieldName", vì vậy "ShownFieldName" được hiển thị trong Danh sách nhưng tôi có thể truy cập mục theo tên nội bộ
dưới dạng field.InternalName là readOnly: Cách thực hiện tôi có thể giải quyết vấn đề đó không?
một lần nữa cảm ơn, Marek. Đã làm việc. –