I am creating a custom WSP in Visual Studio. This solution has several custom content types with custom fields as well as a list instance with content types enabled. Unfortunately, i need to change the static name of a few of my fields & deploy to several different servers.
I have tried the following code:
Feature.Web.Template.xml
<Feature xmlns="http://schemas.microsoft.com/sharepoint/">
<UpgradeActions>
<VersionRange BeginVersion="0.0.0.0" EndVersion="1.0.0.1">
<CustomUpgradeAction Name="RenameField">
<Parameters>
<Parameter Name="FieldID">{060A9145-5D22-4D6C-A049-2438D8E0CDD8}</Parameter>
<Parameter Name="NewName">ProductDescription</Parameter>
</Parameters>
</CustomUpgradeAction>
<CustomUpgradeAction Name="RenameField">
<Parameters>
<Parameter Name="FieldID">{FBDDC10E-4872-4A4D-98C1-E2FD19658D24}</Parameter>
<Parameter Name="NewName">DiscussionAccessOther</Parameter>
</Parameters>
</CustomUpgradeAction>
</VersionRange>
</UpgradeActions>
</Feature>
Feature.EventReceiver.cs
public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, System.Collections.Generic.IDictionary<string, string> parameters)
{
SPWeb web = (SPWeb)properties.Feature.Parent;
switch ( upgradeActionName ) {
case "RenameField":
RenameField(web, new Guid(parameters["FieldID"]), parameters["NewName"]);
break;
}
}
protected void RenameField(SPWeb web, Guid fieldId, string newName) {
if ( web.Fields.Contains(fieldId) ) {
RenameField(web.Fields[fieldId], newName);
}
foreach ( SPList l in web.Lists ) {
if ( l.Fields.Contains(fieldId) ) {
RenameField(l.Fields[fieldId], newName);
}
if ( l.ContentTypesEnabled ) {
foreach ( SPContentType ct in l.ContentTypes ) {
if ( ct.Fields.Contains(fieldId) ) {
RenameField(l.Fields[fieldId], newName);
}
}
}
}
}
private void RenameField(SPField field, string newName) {
field.StaticName = newName;
field.Update();
}
This updates the field in the field gallery, but not the list instance. What am i missing?
Thanks.