场景是我正在尝试添加一个新的网站栏,我需要更新架构定义。第二次执行更新时说找不到该字段,但它在那里,我什至可以在功能激活崩溃后在站点列上看到它
private void AddManagerField(SPWeb currentweb)
{
try
{
//Add new field to Site Columns
string managerFieldName = currentweb.Fields.Add(SponsoringCommon.Constants.FIELDS_SPONSORINGMANAGER_NAME, SPFieldType.User, false);
SPFieldUser managerField = currentweb.Fields.GetFieldByInternalName(managerFieldName) as SPFieldUser;
managerField.Group = SponsoringCommon.Constants.DEFAULT_TAXONOMY_TERMGROUP_NATIONALELOTERIJSPONSORING;
managerField.Update();
SPFieldUser managerField2 = currentweb.Fields.GetFieldByInternalName(managerFieldName) as SPFieldUser;
string schemaXmlWithResourceTokens = managerField2.SchemaXmlWithResourceTokens;
int startIndex = schemaXmlWithResourceTokens.IndexOf("\"", schemaXmlWithResourceTokens.IndexOf("DisplayName=\"")) + 1;
int endIndex = schemaXmlWithResourceTokens.IndexOf("\"", startIndex);
int substringLength = endIndex - startIndex;
string value = schemaXmlWithResourceTokens.Substring(startIndex, substringLength);
schemaXmlWithResourceTokens = schemaXmlWithResourceTokens.Replace(value, "$Resources:SPNLSponsoring,Field_SponsoringManager_Name");
managerField2.SchemaXml = schemaXmlWithResourceTokens;
managerField2.Update();
SPContentTypeId dossierCTID = new SPContentTypeId(SponsoringCommon.Constants.CONTENTTYPES_DOSSIER_ID);
SPContentType dossierCT = currentweb.ContentTypes[dossierCTID];
SPFieldLink managerFieldLink = new SPFieldLink(managerField2);
dossierCT.FieldLinks.Add(managerFieldLink);
dossierCT.Update(true);
}
catch (Exception ex)
{
Logger.LogError("error", "AddManagerField(SPWeb currentweb)", ex);
throw;
}
}