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
System.Exception
System.ApplicationException
Microsoft.SharePoint.SPException
Microsoft.SharePoint.SPContentTypeSealedException
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No
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
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
- 5/24/2010
- Adam Buenz - MVP