I've been working on a new internal portal for my employer using SharePoint 2010. As the project progressed, we experimented with several custom page layouts and, at length, settled on our two favorites.
With the decision final, we reassigned all the pages to the authorized page layouts and proceeded to delete the extras... all except one.
This page layout didn't want to get deleted. I was persistent, but the file was more so.
Type : ItemDeleting SequenceNumber : 1000 Assembly : Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c Class : Microsoft.SharePoint.Publishing.Internal.BlockDeletionOfInUseItemsEventReceiver
function Remove-PageLayout($siteUrl, $layoutName) { $site = Get-SPSite $siteUrl $web = $site.RootWeb $gallery = $web.lists["Master Page Gallery"] $layoutItem = $gallery.Items |? { $_.Name -eq $layoutName } if(!$layoutItem) { throw (new-object IO.FileNotFoundException) } $layoutFile = $layoutItem.File $layoutFile.BackwardLinks |% { if(Test-Page $_.Url) { throw "Cannot delete page because it is referenced by $($_.Url)." } } $receiverType = [Microsoft.SharePoint.Publishing.Internal.BlockDeletionOfInUseItemsEventReceiver] $unregisterMethod = $receiverType.GetMethod("Unregister", [reflection.bindingflags]"Static,NonPublic") $registerMethod = $receiverType.GetMethod("RegisterIfNeeded", [reflection.bindingflags]"Static,NonPublic") $unregisterMethod.Invoke($null, $gallery) $layoutItem.Delete() $registerMethod.Invoke($null, $gallery) $site.Dispose(); } function Test-Page($url) { $site = $web = $null trap [exception] { if($web) { $web.dispose() } if($site) { $site.dispose() } return $false } $site = new-object Microsoft.SharePoint.SPSite($url) $web = $site.openweb() $file = $web.GetFile($url) $result = $file.exists $web.dispose() $site.dispose() return $result }
Remember Me
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, sup, u