none
How to remove 'Content Type' reference from 'Document' library programatically in SharePoint 2013 RRS feed

  • Question

  • I have a requirement to modify the existing 'Site column' of People/ Groups, which allows end user to chose Single user and I need to update the site column to multiple user select through the code.

    I have tried updating the 'Site Column' through code but no use. After lot of research, I found it is not possible to replace existing site column (via same content type).

    As a work around, we can replace the existing content type with Newly created content type containing the same set of site columns(to retain the existing list item values) & then add the required column [i.e,.,(Multiple user select) People picker column. ].

    It works fine but, when I tried to delete the unused existing Site Content Type, using the below code 

    SPContentType contentTypePDelete = spWeb.ContentTypes["PAGEPOLICY"];
    
     SPList lstPages = spWeb.Lists.TryGetList("PAGES");
    
    if (contentTypePDelete != null)
                        { 
                            SPContentTypeId id = lstPages.ContentTypes.BestMatch(contentTypePDelete.Id);
                            //Error throwing Line
                            lstPages.ContentTypes.Delete(id);
                            //Error throwing Line
                            lstPages.Update();
    }
    

    It throws the following Error:

    Content Type is still in use

    What is the correct approach to remove the (existing)Content Type(which is currently not used) in Sp 2013 Document library?

    Saturday, April 18, 2015 10:30 AM

Answers

  • Hi Karthikeyan,

    We cannot remove a content type from library if there any documents associated to it. So we need to identify the documents belonging to the content type and change it to another content type (say "Document") and then we can remove it. Once the new content type is added to library, we can once again change it from Document to your new content type.

    Thanks,

    M. Gubendra Raj

    Saturday, April 18, 2015 2:52 PM