Change Folder Content Type

Last week I had a request to add metadata to document library folders, thanks to this article (How to add a column to SharePoint folders) by Mike Smith I had the answer and before everyone starts I know you shouldn’t be using folders but it was the request.

Here the steps

  1. Go to Site Actions, Site Settings
  2. Click Site Content Types
  3. Click Create
  4. Give the new content type a name such as “Enhanced Folder”
  5. Set the parent content type group as Folder Content Types
  6. Set the parent content type to Folder
  7. Add the new content type to a Group. I put it back in the “Folder Content Types” group
  8. Click OK
  9. Scroll down to the columns section and click Add from new site column
  10. Name the column and set all the usual column options
  11. Repeat for any additional columns (Release Date, etc)
  12. Click OK
  13. Go to your document library
  14. Click Settings and Library Settings, or in 2010 click the Library ribbon tab and then click Library Settings
  15. Click Advanced and set Allow management of content types to Yes and click OK (this may already selected)
  16. Scroll down to Content Types and click Add from existing site content types and add your new folder content type
  17. Go to your library and click the New drop down, or the New button in the Document ribbon, and add your new folder!
  18. Go to the View drop down and click Modify this view and add your new folder meta data columns (you will probably want to move them to just after the Name column)

But, now I have my new content type, I had to update all the folders and sub folders with the new Enhanced Folder content type, PowerShell to the rescue.

$web = Get-SPWeb http://intranet/sites/test
$list = $web.Lists["Test"]
$oldCT = $list.ContentTypes["Folder"]
$newCT = $list.ContentTypes["Enhanced Folder"]
$newCTID = $newCT.ID

for($i=0; $i -le $web.Lists.Count; $i++)
{
   foreach($folder in $list.folders[$i])
   {
      if ($folder.ContentType.Name -eq $oldCT.Name)
      {
         $folder["ContentTypeId"] = $newCTID
         $folder.Update()
      }
   }
}

$web.Dispose()
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s