Error when trying to delete a master page, page layout from SharePoint master pages gallery

 

You might receive an error “This item cannot be deleted because it is still referenced by other pages”. I was searching through the web for a solution then I came across this site. This site gives you a neat little hack !

http://www.katriendg.com/aboutdotnet/2007_1_cannot_delete_page_layout.aspx

 

Reproducing the text from the original site.

Today I ran into an error while creating page layouts using a feature. I made a mistake in the XML that provisions the files to install with the feature for my page layouts. My problem was an incorrect value in the attribute for the content type ID linked to my installed page layout.

After realizing my mistake and correcting it, uninstalling the feature and reinstalling it again the original incorrect page layout was still installed. This seems to be normal in SharePoint. Even when deactivating and uninstalling a page layouts feature these pages still stay in the "Master Page and Page Layout Gallery". I still have to find the right documentation on why this happens but I imagine it has to do with ghosting of the pages.

Now back to my problem. Since the incorrect page layout was still installed and giving me error messages I tried to delete it manually from the gallery. This gave me the following error message:

"This item cannot be deleted because it is still referenced by other pages"

Even if this is not the case (there was no page using this page layout), the problem is mentioned in the following KB article:

http://support.microsoft.com/?kbid=926812

The KB proposes to change the properties of the master page to Hidden. This workaround did not solve my problem since everytime I tried to access the page layout’s Properties screen I got another error message due to my mistake discussed above.

There was however one workaround that solved the problem:

  1. Create a new sub-folder in the master page gallery
  2. Move the page layout to the new folder (I did this by using SharePoint Designer)
  3. In the MOSS interface, delete the complete folder by using the dropdown menu.

Yep, my page layout is finally gone from the gallery!

While my problem was specific to a page layout I think the same solution will work with master pages as well.

Advertisements