Careful When Working with Sealed Site Columns

SharePoint site columns offer a lot of functionality, but with that power comes a few caveats. One of these has to do with the way the sealed attribute works. To illustrate my point, consider the site columns that the Office SharePoint Server Publishing feature adds to the Site Column Gallery of a site collection.

When the publishing feature is activated, the Site Content Type Gallery is populated with the special content types need by the web content management features. These include the Publishing content types like Page, Page Layout and Publishing Master Page as well as the Page Layout content types like Article Page and Welcome Page. Along with these content types, the publishing feature also installs a bunch of specialized site columns, some of which are marked as sealed.

The apparent intention for marking these columns as sealed was to remove the “delete” button from the Change Site Column page in the site column gallery. However, the result is that it also eliminates the “remove” button from the Change Site Content Type Column page that you get when editing a site column in the Site Content Type page.

The following screenshot shows a typical Change Site Content Type Column page for an “Assigned To” site column, which is not marked as sealed. Notice the “remove” button. This is how you would normally detach a column from a content type.

The next screenshot shows the same Change Site Content Type Column page for the “Byline” site column, which is added by the Publishing feature. Notice that there is no remove button, which means it cannot be removed through the user interface once it has been added to a content type.

Sealed content types cannot be removed.

This is a problem because unless they are also marked as “hidden”, users can easily add any of these site columns to their own content types. The ramifications of this can be significant. When you consider that content types can inherit from one another, the results can be downright tragic in certain scenarios.

Say you have a generic content type called “Company Article” and a couple of derived types called “News Article” and “Research Article”. You are not using the publishing features, per se, but the publishing features are enabled and so you see “Byline” as one of the available site columns. You add that column to the generic type so you can access it from your derived types. Later, you decide that Byline should be limited to news articles, so you want to remove it from the Company Article content type. You can’t. Now you’re stuck with a Byline column in the “Company Article” content type and all content types that derive from Company Article because you didn’t know when you added it that this would be an irreversible operation.

Nothing in the UI indicates that the column is sealed. So, it’s quite easy to select a sealed column. Once it’s in, the damage is already done, but the problem won’t show up until you try to remove it.

The following visible columns in the publishing group are marked as sealed, and are therefore problematic when used in a custom content type. There are additional columns in the publishing group which are also marked as sealed, but they are hidden from the UI so they shouldn’t cause a problem:

Article Date, Contact, Contact E-Mail Address, Contact Name, Contact Picture, Scheduling Start Date, Scheduling End Date, Target Audiences, Byline, Image Caption, Page Content, Page Icon, Page Image, Rollup Image, Summary Links, Summary Links 2.

In my opinion, this is a bug in the SharePoint UI. I have always felt that placing the “delete” button for site columns on the Column Edit page was a mistake. This situation confirms that. It should be possible to remove the column from the list of columns shown on the Content Type summary page. You should not have to navigate to the column edit page to remove it from the content type.

A Quick-and-Dirty Workaround

You can still remove “sealed” columns using the SharePoint API. So if you find yourself in a situation where a sealed column must be removed from a content type, you can use code like the following:

void RemoveSiteColumn(SPContentType t, string fieldName)
{
SPField field = t.Fields[fieldName];
if (field != null) {
SPFieldLink link = t.FieldLinks[field.InternalName];
t.FieldLinks.Delete(link.Id);
t.Update();
}
}

Good idea for a custom STSADM command, eh?

<

p class=”zoundry_bw_tags”>

Technorati : , , , ,
Del.icio.us : , , , ,

7 comments

  1. Hi, do you know what happens when a sealed content type is attempted an update upon? Say, you add a column to a parent of a sealed ctype and propagate it to all its heirs? And how that could be fixed?

  2. Good article. I came across this problem when I reinstalled a custom field control and found that all the old content types and site columns were now broken. I ended up developing *very* similar code to remove the column from the content type, but the site column itself still persists and is still broken, which trashes the site column page in the web admin. I am still looking for a way in the API to remove this last peice, but so far no luck. If you know of any way to do this, drop by thomascarpe.com and leave me a comment. 🙂 Thanks.

  3. I found my fix, but there was no solution in code. I just had to tweak the XML in FLDTYPES.xml long enough to get the pages working, then both the API and the admin pages started working properly and I was able to delete the column.<br /><br />I posted details of my struggle here: http://thomascarpe.com/Lists/Posts/Post.aspx?ID=19<br /><br />Your post got me headed in the right direction. There is so little out there that passes for documentation on SharePoint, so it was really valuable to me. Thanks again for your article.

  4. I don’t think the “Sealed” attribute is the culprit here, but rather the CanBeDeleted attribute. For example, the “Primary Phone” has Sealed = true, but we are able to remove it from a content type.<br /><br />All of the Publishing Columns and most of the Page Layout columns have CanBeDeleted set to true. I think it’s purely coincedence that the Sealed attribute is also true.

  5. I have also run into this problem. But my bigger problem is that I don’t have access to the file system. Is there a way to fix this without access to the file system?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.