{"id":2205,"date":"2011-12-25T09:33:34","date_gmt":"2011-12-25T09:33:34","guid":{"rendered":"https:\/\/poiseddevelopers.com\/reality-tech\/?p=2205"},"modified":"2024-04-26T12:08:11","modified_gmt":"2024-04-26T12:08:11","slug":"eliminating-metadata-from-the-folder-content-type","status":"publish","type":"post","link":"https:\/\/poiseddevelopers.com\/reality-tech\/eliminating-metadata-from-the-folder-content-type\/","title":{"rendered":"Eliminating metadata from the Folder Content Type"},"content":{"rendered":"<p>Once again I was compelled to swoop in to fix a managled set of Metadata and Content Types for a key document library.\u00a0 The simplest of the challenges was removing metadata from Folders, or so I thought.\u00a0 In this case, somehow, all the fields in the Document Library were associated with the Folder Content Type, so adding a new folder presented the user with roughly ten fields to complete; which were not needed.<\/p>\n<p>First attempt was to hide the fields, which didn\u2019t succeed:<\/p>\n<pre data-uw-rm-sr=\"\">$Fields=$tContentType.Fields;\r\n$Fields[$Field].set_showinaddform($false);\r\n$Fields[$Field].set_showineditform($false);<\/pre>\n<p>I then tried the old standby of \u00a0trying to remove the field, where $i is the index of the field within the Content Type:<\/p>\n<pre data-uw-rm-sr=\"\">$Fields=$tContentType.Fields;\r\n$Fields.item($i).remove()<\/pre>\n<p>I then tried my usual approach to redo the FieldLinks that is the list of fields to present for forms, by removing the selected fields, to no avail:<\/p>\n<pre lang=\"php\">    $fieldLinks = $tContentType.FieldLinks; #simple shortcut reference $fieldList = New-Object 'System.Collections.Generic.List[System.String]' #new ordered list of fields \r\n# add everything to the list EXCEPT the fields to be removed\r\nfor ($i = 1; $i -le $FieldLinks.Count; $i++) {\r\n  $FieldName=$FieldLinks[$i - 1].Name;\r\n If ($FieldsToEliminate -notcontains $FieldName)  #if this is a field that belongs     \r\n   {$fieldList.Add($FieldName);\r\n}\r\n$FieldLinks.Reorder($fieldList.ToArray())  #convert fields to array as we trigger Reorder method on fields  \r\n$tContentType.Update()\r\nBy this time, I was getting pretty hot under the collar, spending hours wrestling with removing a few fields from a Folder Content Type.  This simple script did the trick.  Here it is as a function.  Note how I defined the parameter types, and also take care to clear and restore the ReadOnly flag, for any Content Type that started out Read-Only:\r\n\r\nFunction Eliminate_Visible_Fields_ContentType( [Microsoft.SharePoint.SPContentType]$tContentType\r\n                                        , [System.string]$tFields\r\n                                        ) {\r\n $originallyReadonly = $tContentType.readonly;\r\n if ($originallyReadonly) {$tContentType.set_readonly($false)};\r\n\r\n $FieldsToEliminate = $tFields.Split(\u201c,\u201d) #convert set of fields into array\r\n $Fields=$tContentType.Fields;\r\n foreach($field in $FieldsToEliminate)     {\r\n   $tContentType.FieldLinks.delete($field); }\r\n Write-Output([System.String] \"Content Types stripped!\")\r\n\r\n $tContentType.Update()\r\n if ($originallyReadonly) {$tContentType.set_readonly($true)};\r\n}<\/pre>\n<p>A few points to note:<\/p>\n<ul>\n<li>The input parameter tFields is a comma separated string of field names<\/li>\n<li>The field name expected is the \u201cInternal\u201d field name.\u00a0 That means the ugly name with the internal hex characters.\u00a0 So my field \u201cProject Num\u201d can be deleted only by referencing \u201cProject_x0020_Num\u201d.<\/li>\n<li>SharePoint Manager can be used to derive the intername field names<\/li>\n<li>Referencing the RootWeb Field list can get you the internal field names programmatically<\/li>\n<li>Trying to delete the public and internal names is safe.\u00a0 Best is to add them both to the list to be deleted; the correct one will be deleted.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Once again I was compelled to swoop in to fix a managled set of Metadata and Content Types for a key document library.\u00a0 The simplest of the challenges was removing metadata from Folders, or so I thought.\u00a0 In this case, somehow, all the fields in the Document Library were associated with the Folder Content Type, [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":940,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[39],"tags":[],"class_list":["post-2205","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-content-types"],"acf":[],"_links":{"self":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts\/2205","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/comments?post=2205"}],"version-history":[{"count":3,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts\/2205\/revisions"}],"predecessor-version":[{"id":3026,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts\/2205\/revisions\/3026"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/media\/940"}],"wp:attachment":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/media?parent=2205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/categories?post=2205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/tags?post=2205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}