Sometimes, you want to make absolutely sure that someone can’t go in and change your content type via the Windows SharePoint Services user interface. If an administrator were to delete or rename columns in your content type this can cause all sorts of issues as things may or may not be prorogated down to the child types. You might also want to ensure that a content type is only created / modified by using a feature and CAML. To solve this, a content type can be marked as sealed and it can only be marked as sealed through the object model. This prevents any casual changes to the content type via the user interface.
The code to seal a content type is pretty simple. Just get a reference to the particular content type you want to change, set Sealed to true and update the content type. In my example, I am just changing a content type off the root of the site collection called Test Content Type. Here is the code.
14 using (SPSite currentSiteCollection = new SPSite("http://moss-server"))
16 SPContentType contentType = currentSiteCollection.RootWeb.ContentTypes["Test Content Type"];
17 contentType.Sealed = true;
Of course there are some things you should know before sealing a content type. As mentioned before, you will not be able to make any changes in the user interface as you can see below. You also have to be a site collection administrator to seal the content type. This means your code has to be executed by a user with appropriate permissions (a console app works fine). You also need to know that sealed content types are not updated through push-down operations. So if a change is made in a SPWeb’s content type and a list’s content type beneath it is sealed, that child content type won’t be updated. You just have to remove all of your seals first.
That is what your content type will look like once it is sealed. This concept also applies to the SPField object (for Site Columns) as well, the code would be quite similar and also makes use of the Sealed property. You can also seal content types at the list level as well. To unseal your content type, just set the sealed property to false and update it again.