This topic has not yet been rated - Rate this topic

SPContentTypeSealedException Class

Represents an exception that occurs when an attempt is made to modify an SPContentType object that is sealed.

System.Object
  System.Exception
    System.ApplicationException
      Microsoft.SharePoint.SPException
        Microsoft.SharePoint.SPContentTypeSealedException

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No
[SerializableAttribute]
public class SPContentTypeSealedException : SPException

If an SPContentType object is sealed, the value of its Sealed property is true.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
SPContentTypeSealedException
Description

The Microsoft.SharePoint.SPContentTypeSealedException class inherits from the Microsoft.SharePoint.SPException class which denotes an exception in SharePoint. This in turn inherits from System.ApplicationException so the error is thrown by a user program rather than the runtime.

SPContentTypeSealedException contains three public, and one protected constructor. The constructors have very specific purposes either:

1) Type-specific logic
2) Type-specific logic and the default message
3) Type-specific logic for inner exceptions
4) Type-specific serialization logic

Usage Scenario

The most ordinary usage of the SPContentTypeSealedException is when performing operations that might fail if SPContentType.Sealed is set to true. This test is most customary when performing sensitive operations such as updating and deleting content types since there are several built-in content types that are sealed and cannot be edited (such as the System (0x) content type).

In the following example, I hydrate a SPContentType object by specifying the name "My Sealed Content Type". Following, I check the SPContentType.Sealed property. If it is true, I throw a new SPContentTypeSealedException with a custom message. 

It is important to note that if you wanted to use the inherent SharePoint .NET resource files you could instead use:SPResource.GetString("ContentTypeSealed", new object[] { this.Name, this.Scope }) 

C# Code Example

using (SPSite site = new SPSite("<SharePoint Url>"))
{
using (SPWeb web = site.OpenWeb())
{
SPContentType contentType = web.ContentTypes["My Sealed Content Type"];
if (contentType.Sealed)
{
throw new SPContentTypeSealedException(string.Format("{0} is sealed!", contentType.Name));
}
else
{
contentType.Delete();
}
}
}

Visual Basic .NET Code Example 

Using site As New SPSite("<SharePoint Url>")
Using web As SPWeb = site.OpenWeb()

Dim contentType As SPContentType = web.ContentTypes("My Sealed Content Type")
If contentType.Sealed Then
Throw New SPContentTypeSealedException(String.Format("{0} is sealed!", contentType.Name))
Else
contentType.Delete()
End If
End Using
End Using

Adam Buenz
SharePoint Foundation MVP - http://www.sharepointsecurity.com