Remove Previously Promoted Fields
I am having trouble removing previously promoted fields from my form library.
Scenario:
InfoPath 2007
SharePoint Server 2007 using Forms Services
I had published my infopath form as a content type and made that content type the default for this form library. I then promoted several fields when I published the form and I gave them custom names in the publishing wizard. I then changed the custom names when I published the next version of the form template (because I decided to call them something different).
The problem is that the old promoted field names are still showing in both the content type and the library along with the new names (I now have twice as many columns as I should have). I was able to delete these extra columns from the content type but they still show up in the library. When editing settings on the library, these columns are not editable (thier names are not clickable). I have deleted all form instances from the library (thinking that maybe an old form instance that used the old names caused them to stick around) but that had no effect.
How on earth do I get rid of these columns that were created by field promotion? I would rather not delete the entire form library because that means recreating my workflows that I have built on the library.
Risposte
The reason you can't delete these fields is because InfoPath marks the fields as read-only when it creates them on the content type. This setting is carried over to the document library.
I ran into a similar situation on one of my document libraries that had a large number of documents that I didn't want to delete. I ending up using the SharePoint API to set the read-only flag on the columns to TRUE, then I could delete them from the doc lib's Settings page.
PowerShell is a useful way to fix these kinds of problems, as it allows you to interactively create instances of objects and navigate an object model. Here's an example of a series of PowerShell commands that you can use to change the read-only setting on a field.
Code Snippet# Load the main SharePoint assemblies
[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c");
[System.Reflection.Assembly]::Load("Microsoft.SharePoint.Workflows, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c");
# Get an SPWeb reference using the URL of the site
$url = "http://server"
$siteCollection = new-object Microsoft.SharePoint.SPSite $url
$site = $siteCollection.OpenWeb();
# Get a reference to the SPField for the column we want to get rid of.
$doclib = $site.Lists["MyDocumentLibrary"];
$field = $doclib.Fields.GetFieldByInternalName("fieldinternalname");
# Change the field settings
$field.ReadOnlyField = $FALSE;
$field.Update();
# Dispose of the SPSite and SPWeb instances to release resources
$site.Dispose();
$siteCollection.Dispose();
Tutte le risposte
The reason you can't delete these fields is because InfoPath marks the fields as read-only when it creates them on the content type. This setting is carried over to the document library.
I ran into a similar situation on one of my document libraries that had a large number of documents that I didn't want to delete. I ending up using the SharePoint API to set the read-only flag on the columns to TRUE, then I could delete them from the doc lib's Settings page.
PowerShell is a useful way to fix these kinds of problems, as it allows you to interactively create instances of objects and navigate an object model. Here's an example of a series of PowerShell commands that you can use to change the read-only setting on a field.
Code Snippet# Load the main SharePoint assemblies
[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c");
[System.Reflection.Assembly]::Load("Microsoft.SharePoint.Workflows, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c");
# Get an SPWeb reference using the URL of the site
$url = "http://server"
$siteCollection = new-object Microsoft.SharePoint.SPSite $url
$site = $siteCollection.OpenWeb();
# Get a reference to the SPField for the column we want to get rid of.
$doclib = $site.Lists["MyDocumentLibrary"];
$field = $doclib.Fields.GetFieldByInternalName("fieldinternalname");
# Change the field settings
$field.ReadOnlyField = $FALSE;
$field.Update();
# Dispose of the SPSite and SPWeb instances to release resources
$site.Dispose();
$siteCollection.Dispose();
- Thank you very much for the explanation and powershell code. You have saved me some real headaches. I hope that MS can provide a way to avoid this issue in a future update of InfoPath/SharePoint.
- Thanks David.

