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 site column that was created some time ago, and that column was added to a content type. Then many lists were created using that content type.

Later they decided that field should not exist anymore. The field was removed from the content type manually, but it exists still on the site columns.

When a new list is created based on the content type, the field is added to new lists, even though in old lists its not there.

I know that I shouldnt edit the content type schema, I wonder if I can safely delete the site column manually and thats it?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You should remove the column and update your content type as well.

You can do that in two way at least. By a feature activation:

string contentTypeName = "MyCT";
try
{
    var contentType = site.RootWeb.ContentTypes[contentTypeName];
    if (contentType == null)
        return;

    var fields = site.RootWeb.Fields;
    if (fileds.ContainsField("FieldName"))
    {
        var field = fileds.GetField("FieldName");
        if (!contentType.Fields.ContainsField("FieldName"))
        {
            contentType.FieldLinks.Delete("FieldName");
            contentType.Update();
        }
    }
}}

another way is by powershell:

$web = Get-SPWeb http://portal
$ct = $web.ContentTypes["MyCT"]
$spFieldLink = New-Object Microsoft.SharePoint.SPFieldLink ($web.Fields["FieldName"])
$ct.FieldLinks.Delete($spFieldLink.Id)
$ct.Update()
$web.Dispose()
share|improve this answer

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.