Exception when programmatically copying content type

Posted by BeraCim on Stack Overflow See other posts from Stack Overflow or by BeraCim
Published on 2010-04-17T05:29:56Z Indexed on 2010/04/17 5:33 UTC
Read the original article Hit count: 334

Filed under:
|

Hi all:

I'm getting exceptions when copying content type from one web to another:

foreach (SPContentType destinationWebCt in destinationWeb.ContentTypes)
{
    destinationWeb.ContentTypes.Add(existingWebCt);
    destinationWeb.Update();
}

existingWebCt is the content type from another web e.g. /Site/Web. destinationWeb is the web that I wish to copy the content type to e.g. /Site/DestinationWeb.

I got the SPException that says something like could not copy content type to scope.

Then I decided to replace all "ContentTypes" to "AvailableContentTypes", but then I got the SPException saying this collcetion could not be modified.

So how can I copy a content type to another web?

Thanks.

© Stack Overflow or respective owner

Related posts about sharepoint

Related posts about sharepoint2007