3

I used the following code to add a content type directly from the ContentType Hub. After running the script, Content Type is added to the Document Library but missing in the Site Gallery.

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    using (SPSite siteCTH = new SPSite(ContentHubUrl))
    {
        using (SPWeb webCTH = siteCTH.OpenWeb())
        {
            eCTDocument = webCTH.ContentTypes["MyContentType"];

        }
    }
    using (SPSite site = new SPSite(CurrentWebUrl))
    {
        using (SPWeb web = site.OpenWeb())
        {               
           SPList docLib = web.Lists[new Guid(libraryGuid)];
           docLib.ContentTypes.Add(eCTDocument);
        }
    }
});

So I am not able to re-use the Content Type which I have added to the document Library.

Why the above code is not adding the Content Type in the Site Gallery?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.