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 created a content-type and applied it inside a document library. Now, if I go to the conent-type gallery and delete one of the fields, and then go back to the library and view the available columns, I still see the field I deleted listed as a possible column.

How do I update this to match? I don't want to delete the content-type (like in this post); I just want the deployed columns in that content-type to match the current content-type.

share|improve this question

1 Answer 1

up vote 6 down vote accepted

Next time you perform the changes to the ContentType make sure to push changes to the lists while updating the ContentType.

For now, you might need to perform some clean-up job here, just to make sure the field is deleted from all the lists, with your Custom ContentType. Use the following PowerShell script for clean-up! Vårsegod :)

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
$site = Get-SPSite "http://your.site.com"
foreach($web in $site.AllWebs)
{ 
    #iterates through all the Lists        
    for ($i = 0; $i -lt $web.Lists.Count; $i++) 
    { 
      $list = $web.Lists[$i];                               
      $MyListContentTypes = $list.ContentTypes                                                          
      if ($MyListContentTypes -ne $null)
      {

         $ct = $list.ContentTypes["You Desired Content Type Name"]                                      
         if($ct)                                                            
         {

             Write-Host "In list Content Type and deleting the field"  $ct.Fields["You Field Name"].Id;
             $ct.FieldLinks.Delete($ct.Fields["You Field Name"].Id)                                  
             $ct.Update()
         }      
       }
    }     
  }

Edit: How to push down changes to all the Content types via SharePoint Server Object Model:

using (SPWeb oWebsite = new SPSite("http://MyServer/sites/MySiteCollection/MyWebSite").OpenWeb())
{
    SPList oList = oWebsite.GetList("MyWebSite/Lists/MyList");
    SPFieldCollection collFields = oWebsite.Fields;

    string strNewColumn = collFields.Add("MyNewColumn", SPFieldType.Text, false);

    SPFieldLink oFieldLink = new SPFieldLink(fields[strNewColumn]);
    SPContentType oContentType = oList.ContentTypes["Specification"];
    oContentType.FieldLinks.Add(oFieldLink);

    oContentType.Update(true);
}

Edit 2: Update a Content Type using PowerShell:

  Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
    //get the specific Root web
    $spweb= Get-SPWeb "http://your.site.com"
    //get the fields collection
    $fields = $spWeb.Fields
    //get the specific field
    $field = $fields.GetFieldByInternalName("Name of you field")
    //get the specific Content Types from Root Web
    $contentType = $spWeb.ContentTypes["You Content Type"]
    //delete a field from a Content Type
    $contentType.FieldLinks.Delete($field) 
   //add a field to a Content Type
    $contentType.FieldLinks.Add($field)
    //update the Content Type and push changes to the children                                     
    $contentType.Update($true)
share|improve this answer
    
Thanks for the script. I tried the "push changes to the lists" thing, but the columns remain. If I go to the library and view the content-type, I can still see the column present - just the source is no longer listed. –  BGM Nov 22 '12 at 22:28
    
It depends how are you are pushing down the changes. When you edit a site content type through the user interface and make a change on a content type settings page, all the settings contained on that page are overwritten during the push-down operation. However, using the object model provides greater granularity in push-down operations. As you make changes to a site content type through the object model, your code is actually making those changes to the in-memory representation of the site content type. Read more: msdn.microsoft.com/en-us/library/ms442695(v=office.14).aspx –  Falak Mahmood Nov 22 '12 at 22:36
    
Okay, Mr. Mahmood, I'll give that a try and tell you how it goes. When you say, "using the object model" - do you mean "using" it via powershell? –  BGM Nov 22 '12 at 22:47
    
Object model mean using the SharePoint server object model. I have updated my response. Alternatively, you can also use PowerShell to accomplish the same task. –  Falak Mahmood Nov 22 '12 at 22:52
1  
Much Thanks! I appreciate that! –  BGM Nov 23 '12 at 14:30

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.