If you use a content type that has been published from a Content Type Hub in your document library then if you decide to delete that content type from the document library you might experience the problem - for some reason published content types are made read only when you add them to libraries.
Example
1. We have got a document library with published content type "BaseDocument":
2. If we try deleting it from the library we are getting an error:
Example
1. We have got a document library with published content type "BaseDocument":
2. If we try deleting it from the library we are getting an error:
"The content type "X" at "Document Library Y" is read only."
Solution
Using SharePoint API we can update the ReadOnly property and then delete the content type.
Here's the PowerShell script sample:
$siteurl = "http://siteurl"
$ctname = "BaseDocument"
$libname = "Shared Documents"
$site = Get-SPSite $siteurl
$web = $site.OpenWeb()
$list = $web.Lists[$libname]
$ct = $list.ContentTypes[$ctname]
$ct.ReadOnly = $false
$ct.Update()
$list.ContentTypes.Delete($list.ContentTypes[$ctname].Id)
$list.Update()
Enjoy.
Comments
Post a Comment