none
can we reference a master page in layouts for TeamSites ? RRS feed

  • Question

  • Hi All,

     

     

     

     I tried to set a master page thru code -

                        web.AllowUnsafeUpdates = true;

                        web.MasterUrl = "/_layouts/custom1/my-v4.master";
                        web.CustomMasterUrl = "/_layouts/custom1/my-v4.master";
                        web.Update();

     

    im running this code in a Console app to check - im not getting any error

     

    and later when I access the site - im getting  The referenced file '/_layouts/custom1/my-v4.master' is not allowed on this page.  error.

     

     

                   Tried changing the  

        web.MasterUrl =     with lot of other possible values  - but the same error comes, when I open the site.

     

     

    web.MasterUrl = " _layouts/v4.master " ;  -> this line throws an error  : Invalid URL: _layouts/v4.master   - > I tried to reference the OOB master page in layouts - which never open in the page.

     

     

    My doubt is, is it really possible to set Master/CustomMaster page in the layouts  folder for TEAMSites ??

    Its a OOB Teamsite - that is getting provisioned im adding a feature to do this work. Im not getting any error in this code - but when I access the site, im getting the error : The referenced file '/_layouts/custom1/my-v4.master' is not allowed on this page.

     

    my-v4.master here is a copy of OOB V4.master (w/o any change).

    Thursday, January 20, 2011 2:05 AM

Answers

  • The master page for any regular site pages stored in the content database must also be in the content database.  Normally you would deploy the master page the the masterpage gallery and then activate it using a feature reciever for a team site.  Since _Layouts is in the file system you can't use master pages stored there for anyting other than application pages stored there.
    Paul Stork SharePoint Server MVP
    • Proposed as answer by Sharepoint Dave Thursday, January 20, 2011 8:57 AM
    • Marked as answer by Wayne Fan Thursday, January 27, 2011 2:44 AM
    Thursday, January 20, 2011 3:14 AM
  • If the masterpage is added via a Feature then the physical copy will be in the Feature folder of the SharePoint root.  Activating the feature in a web or site collection will add a reference to the master page to master page gallery of that website, but the physical copy will still be the one in the Feature folder.  That won't change unless you edit the copy in the master page gallery using SharePoint Designer.  If you later upgrade the copy in the feature folder all the sites will use the updated copy.
    Paul Stork SharePoint Server MVP
    • Marked as answer by Wayne Fan Thursday, January 27, 2011 2:44 AM
    Thursday, January 20, 2011 12:54 PM

All replies

  • The master page for any regular site pages stored in the content database must also be in the content database.  Normally you would deploy the master page the the masterpage gallery and then activate it using a feature reciever for a team site.  Since _Layouts is in the file system you can't use master pages stored there for anyting other than application pages stored there.
    Paul Stork SharePoint Server MVP
    • Proposed as answer by Sharepoint Dave Thursday, January 20, 2011 8:57 AM
    • Marked as answer by Wayne Fan Thursday, January 27, 2011 2:44 AM
    Thursday, January 20, 2011 3:14 AM
  • Thanks Paul. I almost came to a conclusion after long fighting that only Application pages can read the master page in layouts :)

    Next question is :

    What if I have 100s of websites using the same master page ( but seperate copy ) and I want to change all of them ??

    Thursday, January 20, 2011 4:04 AM
  • 100s of websites using the same master page

    IF it is Same Master Page Why you need to keep Separate Copy. Add a master page in Physical Layout Folder and refer that master page.

     

    In your previous case open the MasterPage Gallery in Sharepoint Designer and add the desired Master Page and Refer it.

    Thursday, January 20, 2011 5:40 AM
  • Hey Mohan,

     

    Thanks.  Thats what I was trying to do :)

    When you keep the master page in Layouts and set that in the MasterUrl/CustomUrl property of the Site, its not taking it. :)

    Thursday, January 20, 2011 6:27 AM
  • I would recommend a feature receiver on activation. with about 20 lines of code you can loop through every site in the site collection and apply the master page. This is how I do branding for Sharepoint Foundation sites for custom master pages. You can deploy it to the sandbox or the farm.

    here is a nice article on how to do it

    http://msdn.microsoft.com/en-us/library/gg447066.aspx

     

    Thursday, January 20, 2011 6:55 AM
  • If the masterpage is added via a Feature then the physical copy will be in the Feature folder of the SharePoint root.  Activating the feature in a web or site collection will add a reference to the master page to master page gallery of that website, but the physical copy will still be the one in the Feature folder.  That won't change unless you edit the copy in the master page gallery using SharePoint Designer.  If you later upgrade the copy in the feature folder all the sites will use the updated copy.
    Paul Stork SharePoint Server MVP
    • Marked as answer by Wayne Fan Thursday, January 27, 2011 2:44 AM
    Thursday, January 20, 2011 12:54 PM