locked
Programmatically Hide Master Pages from Site Master Page Settings page? RRS feed

  • Question

  • Hi,

    I know there is a field you can check when you edit the properties of a Master Page in the Master Page Gallery to set a Master Page to hidden but ... can anyone think of a way to programmatically hide specific Master Pages from the Site Master Page Settings page?

    Maybe this should be two questions:

    1. How do I programmatically access a Master Page in a Master Page Gallery?
    2. Is there a property that can be set that will hide the page from the Site Master Page Settings page?
    Friday, August 27, 2010 5:33 PM

Answers

  • If I was in your situation I would approach the problem in a couple different ways...

    First and foremost I would make sure you have some sort of governance in place that clearly states that only your master page should be used. If they change it to a different master page then, sorry! you lose your site owner priveledges. Follow this up with site owner training that mentions this as well.

    For a more hands on approach, you could (not saying its the best idea), delete the out of the box master pages upon site creation - which could probably be done as an event receiver upon site creation. Everything except for default.master of course. Then when your master page is applied, only yours and the default would be available.

    Or instead of hiding them, see (I'm not sure if you can) if you could hook into the event that is fired when a new master page is applied to a site. If the master page being applied is not equal to your master page, then prevent it from changing. Hope this helps.

    • Marked as answer by Aaron Han - MSFT Sunday, September 5, 2010 3:19 AM
    • Unmarked as answer by Devignly Tuesday, September 7, 2010 2:06 PM
    • Marked as answer by Devignly Tuesday, November 16, 2010 10:50 PM
    Monday, August 30, 2010 2:30 PM

All replies

  • Why do you want to hide master pages?

    I was thinking you could use item security (the master page gallery is just a document library), but who are you going to hide it from.  The web administrator already has Full Control site permissions.  I guess you could only allow a site collection administrator have access.  That would certainly hide them.

    I think the Master Page gallery has an approval workflow.  You could enable publishing, and then only master pages that have been approved (published) could be used by the web administrator.

    I'm not aware of a property that lets you hide master pages.  But if there is such a field, you just need to access the gallery (you can get a list reference using its URL through the SPWeb object), get a hold of the item, and set that field (property).

    ~site/_catalogs/masterpage


    Brian Bedard, MCTS - pioneeringsharepoint.blogspot.com - Twitter:@tigertoy

    Sunday, August 29, 2010 2:06 AM
  • I'd like to hide the OOB Master Pages so the Site Owners don't go in there and change them. We have one branded MP and if the Owners go in and flip it to BlueBand (or whatever) it's going to look unbranded.

    Thanks for the help; I'll take a look at GetListFromUrl and report back. I think I may run into problems though because I'm not sure if the FeatureActivated code is going to fire (maybe it doesn't need to though) when a new Site (not Site Collection) is created and the Feature is stapled.

    Monday, August 30, 2010 1:12 PM
  • If I was in your situation I would approach the problem in a couple different ways...

    First and foremost I would make sure you have some sort of governance in place that clearly states that only your master page should be used. If they change it to a different master page then, sorry! you lose your site owner priveledges. Follow this up with site owner training that mentions this as well.

    For a more hands on approach, you could (not saying its the best idea), delete the out of the box master pages upon site creation - which could probably be done as an event receiver upon site creation. Everything except for default.master of course. Then when your master page is applied, only yours and the default would be available.

    Or instead of hiding them, see (I'm not sure if you can) if you could hook into the event that is fired when a new master page is applied to a site. If the master page being applied is not equal to your master page, then prevent it from changing. Hope this helps.

    • Marked as answer by Aaron Han - MSFT Sunday, September 5, 2010 3:19 AM
    • Unmarked as answer by Devignly Tuesday, September 7, 2010 2:06 PM
    • Marked as answer by Devignly Tuesday, November 16, 2010 10:50 PM
    Monday, August 30, 2010 2:30 PM
  • Thank you Aaron for trying to be helpful and mark what appeared to be an old thread with an answer. Rest assured, I'm still looking into the proposed solutions.

    ChricsC, while I would like to be able to just tell folks "hey don't mess with the MP or I'm going to yank your privileges", I can't do that to the Executive Management of our company :P

    When you say "add an event receiver upon site creation" where would I actually add this? I guess I Feature Staple and then do it in FeatureActivated (I have to set the scope to Web though, right?). Sorry, I'm so used to doing everything at the Site scope so that we can use SharePoint Solution Installer.

    Tuesday, September 7, 2010 2:20 PM
  • Hi Devignly,

    Have you got the solution for this?

    I am facing the same problem.

    Let me know if you got the solution.

    Thanks.

    Tuesday, June 6, 2017 1:49 PM

  • So,Finally i got the solution.
    To solve this issue you have to make changes in element.xml file.
    <File Path="MasterPageGalleryModule\xyz.master" Url="xyz.Configuration.master" Type="GhostableInLibrary">
          <Property Name="Title" Value="xyz Masterpage" />
          <Property Name="UIVersion" Value="15" />      
          <Property Name="ContentType" Value="$Resources:cmscore,contenttype_masterpage_name;" />
          <Property Name="PublishingHidden" Value="TRUE" />
        </File>
    To hide master page you have to add new property i.e. PublishingHidden and set its value "TRUE".

    Make sure that Publishing feature should be activated for particular sitecollection before deployment.
    Friday, June 16, 2017 7:25 AM