Очередной капкан.
При добавлении SPFieldLookup-полей к списку list в примерах рекомендуют нечто вроде:
list.Fields.AddLookup(fieldName, lookupListID, fieldRequired);
SPFieldLookup newfield = list.Fields[fieldName] as SPFieldLookup ;
newfield.LookupField = lookupFieldName;
SPFieldLookup newfield = list.Fields[fieldName] as SPFieldLookup ;
newfield.LookupField = lookupFieldName;
Всё это проходит на примерах, где поле называется Title.
На самом деле, приходится использовать такой код:
AddLookup(list, fieldName, lookupListID, fieldRequired, lookupFieldName);
SPFieldLookup newfield = list.Fields[fieldName] as SPFieldLookup;
AddLookup(list, fieldName, lookupListID, fieldRequired, lookupFieldName);
SPFieldLookup newfield = list.Fields[fieldName] as SPFieldLookup;
...
string AddLookup(SPList list, string FieldName, Guid LookupListID, bool FieldRequired, string LookupFieldName) {
XmlDocument fxml = new XmlDocument();
XmlElement xf = fxml.CreateElement("Field");
xf.SetAttribute("DisplayName" , FieldName);
xf.SetAttribute("Type", "Lookup" );
xf.SetAttribute("Required", FieldRequired.ToString ());
xf.SetAttribute("List", LookupListID.ToString("B" ));
xf.SetAttribute("ColName", "int1" );
xf.SetAttribute("ShowField", LookupFieldName);
return list.Fields.AddFieldAsXml(xf.OuterXml);
}
XmlDocument fxml = new XmlDocument();
XmlElement xf = fxml.CreateElement("Field");
xf.SetAttribute("DisplayName" , FieldName);
xf.SetAttribute("Type", "Lookup" );
xf.SetAttribute("Required", FieldRequired.ToString ());
xf.SetAttribute("List", LookupListID.ToString("B" ));
xf.SetAttribute("ColName", "int1" );
xf.SetAttribute("ShowField", LookupFieldName);
return list.Fields.AddFieldAsXml(xf.OuterXml);
}
Комментариев нет:
Отправить комментарий