SharePoint: Error Unregistering EventReceiver in ContentType

I am having problems registering some eventreceivers of the contenttype form. Content and recipients have been deployed and registered by me, so I am not trying to remove any MOSS built-in or internal tools.

I am trying to archive this with the following code snippet:

using (SPSite site = new SPSite("http://wssdev06/"))
        {
            using (SPWeb web = site.RootWeb)
            {
                // web.AllowUnsafeUpdates = true;

                SPContentType type = web.AvailableContentTypes[<ContentTypeName>];

                while (type.EventReceivers.Count > 0)
                {
                    type.EventReceivers[0].Delete();                        
                }

                type.Update();

                // web.AllowUnsafeUpdates = false;
            }
        }

Unfortunately, the command "type.Update ()" throws an exception, telling me that the collection cannot be changed. As you can see in the code, I have already tried different things to solve this problem, as I allow insecure updates or run this code with elevated privileges. But I always get the same exception.

So what am I doing wrong?

+3
3

, "AvailableContentTypes" READ-ONLY.

ContentTypes, .

,

.

+6

? . SchemaXml . , , .

0

type.ReadOnly = false, .

, SPWeb - . Roger Lamb .

0

Source: https://habr.com/ru/post/1703906/


All Articles