Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I need to attach an event receiver to a content type created by SharePoint:

        FolderCT.EventReceivers.Add(SPEventReceiverType.ItemAdding, SharepointReceiversAssemblyName, CTReceiverName);
        FolderCT.Update();

Unfortunately I get the error:

Folder at "/" is sealed

So, to go around the problem - I'm running the whole snippet under elevated privileges, and I'm setting Sealed to false. Is this a bad idea?

        SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            SPContentType FolderCT = web.ParentWeb.ContentTypes[SPBuiltInContentTypeId.Folder];
            FolderCT.Sealed = false;
            FolderCT.Update();

            FolderCT.EventReceivers.Add(SPEventReceiverType.ItemAdding, SharepointReceiversAssemblyName, CTReceiverName);
            FolderCT.Update();

            FolderCT.Sealed = true;
            FolderCT.Update();
        });
share|improve this question

1 Answer 1

up vote 4 down vote accepted

As long as you reseal it again, as you do, I do not see a problem.

Here's a snippet regarding the purpose of sealing:

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.

from http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2009/03/11/how-to-seal-a-content-type.aspx

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.