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 have a feature that adds two site columns to a content type on activation. On deactivation it's supposed to delete them, but I'm getting the following error: "Site columns which are included in content types or on lists cannot be deleted. Please remove all instances of this site column prior to deleting it."

        SPWeb web = properties.Feature.Parent as SPWeb;
        SPContentType cType = web.ContentTypes[Constants.ClientContentTypeName];

        cType.FieldLinks.Delete(Constants.DebtMgmtClientID);
        cType.FieldLinks.Delete(Constants.DebtMgmtCompanyID);
        cType.Update();

        web.Fields.Delete(Constants.DebtMgmtClientID); // This line throws the error
        web.Fields.Delete(Constants.DebtMgmtCompanyID);

I guess I'm doing it in the wrong order. Can anyone help?

Thanks in advance.

share|improve this question
    
Is this SP2010 or 2007? –  Colin Jun 9 '11 at 21:06
1  
Is it possible that another list or content type is using these site columns? –  Laurie Jun 9 '11 at 21:06
add comment

1 Answer

You need to remove the Column from every content type that may be using it. For example: If you created a column, and bound it to the Document content type, and pushed it down to all of its children, you'll need to remove it from every one of those children before deleting the custom column.

share|improve this answer
add comment

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.