in

Dot Net Mafia

Group site for developer blogs dealing with (usually) .NET, SharePoint, Office 365, Mobile Development, and other Microsoft products, as well as some discussion of general programming related concepts.

This Blog

Syndication

Archives

Corey Roth [MVP]

A SharePoint MVP bringing you the latest time saving tips for SharePoint 2013, Office 365 / SharePoint Online and Visual Studio 2013.

How to: Seal a Content Type

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"))

   15             {

   16                 SPContentType contentType = currentSiteCollection.RootWeb.ContentTypes["Test Content Type"];

   17                 contentType.Sealed = true;

   18                 contentType.Update();

   19             }

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.

ContentTypeSealed

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.

Comments

 

Siyasanga said:

Corey

Just wanna ask you a small question, on the dilogue box(edit form) of the drop off library where you choose a content type when uploading a document to a recod center, would it be possible to change the dropdown field name from "Content Type" to something else ? When users are choosing a content type to route thier records, I don't want it to say "Content Type", I want it to display whatever I changed it to.

June 14, 2011 4:14 AM
 

CoreyRoth said:

I think you are stuck with whatever the content type's name is in this case.

June 20, 2011 4:14 PM
 

R??f??rences pour D??veloppement en SharePoint | BLOC NOTE POUR D??VELOPPEURS SHAREPOINT said:

Pingback from  R??f??rences pour D??veloppement en SharePoint  | BLOC NOTE POUR D??VELOPPEURS SHAREPOINT

July 8, 2013 1:59 PM

Leave a Comment

(required)  
(optional)
(required)  
Add

About CoreyRoth

Corey Roth is an independent SharePoint consultant specializing in ECM, Apps, and Search.
2015 dotnetmafia.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems