Apply custom master page on a subsite

Hi;
I try to apply a custom master page on a new subsite but without success (any impact) :
My code is :
web.AllowUnsafeUpdates = true;
SPWeb newSite = web.Webs.Add(name, name, name, Convert.ToUInt16(1036), template, false, false);
newSite.Navigation.UseShared = true;
newSite.AllProperties["__InheritsCustomMasterUrl"] = "False";
newSite.CustomMasterUrl = curItem["SiteUrl"] + "/_catalogs/masterpage/rep/Generic.master";
newSite.AllowUnsafeUpdates = true;
newSite.Update();
newSite.Close();
Regards;

hi,
try this 
SPSecurity.RunWithElevatedPrivileges(delegate
using (SPSite objSPSite = new SPSite(SPContext.Current.Web.Url))
using (SPWeb objSPWeb = objSPSite.OpenWeb())
objSPWeb.AllowUnsafeUpdates = true;
objSPWeb.MasterUrl = curItem["SiteUrl"] + "/_catalogs/masterpage/rep/Generic.master";
objSPWeb.Update();
objSPWeb.AllowUnsafeUpdates = true;
Whenever you see a reply and if you think is helpful,Vote As Helpful! And whenever you see a reply being an answer to the question of the thread, click Mark As Answer

Similar Messages

  • Custom master page issue in subsites

    Greetings!
    I've run into an oddity with a custom master page on my SharePoint 2013 Enterprise server. I copied the html for the seattle master page, renamed it so it wouldn't change the seattle master, made an addition to it to add a reference to a custom css
    file, then threw it back up on the site so SP would make a new .master file with it. I created a new web app and site collection, put the custom css file in the Style Library and added the custom master page to the Master Pages.
    So, all that being done, I changed the look of the top level site to use the new master page and it looks great and seems to be working as expected. We've got a number of subsites planned for underneath this top level site, I'm thinking no problem, just
    put the custom master file in the master pages and we'll be good. So I create a subsite, put the custom master page in the subsite's Master Pages, change the look. The master page and custom css apply and it looks good, but, then the problem starts.
    When I go into a document library and change a view or add a view or delete a view I get back an odd response page from SP. In the url I see this: https://topsite/subsite/_vti_bin/owssvr.dll?CS=65001
    and in the body of the message: 69|pageRedirect|owssvr|https://topsite/subsite/Shared%20Documents/Forms/AllItems.aspx|
    When I go back into the subsite, whatever change I was attempting when I get these results worked fine.
    So, why does my custom master page work fine on the top level, but not on the subsites? If I switch the subsite back to the Seattle.master, the oddity goes away, so that tells me it's something to do with my custom master page and/or custom css. I did
    some searching for owssvr.dll?CS=65001 and didn't see anything that helped. I checked IIS and the web.config file and don't have ASP.net tracing on that I could find.
    All that the custom css is doing is increasing the size allowable for the site icon (.ms-siteicon-img) to allow for a larger icon (180px square) and it pushes the side Nav Box down a bit to make room for the larger icon and changes the font size for the
    side Nave Box (#sideNavBox). Since it works on the top site, I'm not suspecting the css, but, it's not making sense to me why the custom master page wouldn't work in subsites either.
    I ran into this issue earlier, it was showing up when deleting folders from the document library. I thought I'd made a boo-boo somewhere in creating the custom master page, or how I'd added it, or something (kind of a learn as I go situation here), so I
    deleted the entire web app and recreated it, hoping for a clean start and a good master page and everything would be good. Guess I'm still missing something.
    I swear that the ONLY change I made to the seattle html file for my custom page was to add this line just below the corev15.css line: <!-- SPM:<SharePoint:CssRegistration Name="/Style Library/skcustom.css" after="corev15.css" runat="server"/>-->
    So, that's my sad story. Any suggestions, other than to punt on the custom master page?
    Thanks!
    Steven

    Thanks. I've been experimenting with this for a few days now, and there's lots I don't understand about why and such, but your process above works. That's a big load off me right now and I really appreciate it. I'm going to be able to survive the initial
    roll-out and implementation of the new site. Going forward, I've got lots to learn and find out, I've already heard that there's a desire to really redesign the master page for the site and subsites, way beyond the little CSS customization I did. Fun.
    If you've got a little time though, perhaps you can provide some explanation. If not, no problem.
    On step 6, when I do as you detail, click the System Master Page and reset all the subsites, it seems to work fine with my custom master page. If I do that with the Site Master Page settings, my custom page causes the redirect issue in the subsites again.
    This is whether I do the Site Master Page by itself, or in conjunction with the System Master Page settings. If I revert back to the Seattle master page in the Site Master Page settings and my custom pate in the System Master Page, the issue goes away again.
    It is completely messing with my head, trying to figure out why that would be, and this is all beside trying to figure out why adding the one little CSS reference to the Seattle master to create my master page breaks things (sometimes!).
    Just fyi, what I've ended up with for now is pulling my custom master page out of the system and using the Alternate CSS URL to add my custom CSS to the Seattle master page on the sites. As I thought about all this, I decided I didn't want to leave the breakable
    custom page out there for some unsuspecting site manager to accidentally pick and get everyone screaming about the broken sites.
    Thanks again,
    Steven

  • Apply custom master page for a new sub site in programming

    Hi;
    How Apply a custom master page for a new subsite ?
    My code is as follows but it not working : the master page is not applied ?
    SPWeb newSite = web.Webs.Add(name, name, name, Convert.ToUInt16(1036), "{815BF557-AFE0-42B4-92A1-A8A56011EDBF}#LaPoste.DTC.ModeleSite", false, false);
    newSite.AllProperties["__InheritsCustomMasterUrl"] = "False";
    newSite.CustomMasterUrl = "/_catalogs/masterpage/iDtc/iDtcGeneric.master";
    newSite.AllowUnsafeUpdates = true;
    newSite.Update();
    Regards

    try this:
    foreach (SPWeb site in siteCollection.AllWebs) {
    if (site.Title.ToString() == "Reporting Portal")
    site.MasterUrl = WebAppRelativePath + "_catalogs/masterpage/Branding101.master";
    //site.CustomMasterUrl = WebAppRelativePath + "_catalogs/masterpage/Branding101.master";
    site.AlternateCssUrl = WebAppRelativePath + "Style%20Library/Branding101/Styles.css";
    site.SiteLogoUrl = WebAppRelativePath + "Style%20Library/Branding101/Images/Logo.gif";
    site.UIVersion = 4;
    site.UIVersionConfigurationEnabled = false;
    site.Update();

  • Sharepoint 2013 - Error while applying custom master page.

    I am getting following error on my sharepoint 2013 site on applying a custom master page.
    System.ArgumentNullException: Value cannot be null.  Parameter name: ribbon    at Microsoft.SharePoint.WebControls.RibbonTrimmer..ctor(SPRibbon ribbon)     at Microsoft.SharePoint.WebControls.SPPageStateControl.OnInit(EventArgs e)
        at System.Web.UI.Control.InitRecursive(Control namingContainer)     at System.Web.UI.Control.AddedControl(Control control, Int32 index)     at Microsoft.SharePoint.WebPartPages.WikiEditPage.OnLoad(EventArgs e)    
    at System.Web.UI.Control.LoadRecursive()     at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
    Does anyone know whats wrong with my custom master page?

    Hi,
    please check if its properly deployed.
    Refer the similar thread below.
    http://social.technet.microsoft.com/Forums/en-US/f07ce2f6-6607-4764-8c12-10de4ae1d635/systemargumentnullexception-value-cannot-be-null-parameter-name-ribbon?forum=sharepointgeneralprevious
    Please remember to click 'Mark as Answer' on the answer if it helps you

  • Applying custom master page on layout pages

    I am applying my custom master page on application layout pages which I am deploying using visual studio. My issue is; I have to copy my custom master page in the same directory where my layout pages exist otherwise its not working.
    I want to deploy my custom master in the default master page directory and refer it to my layout pages.
    is it possible or I have to copy my custom master page in the layout page directory ????

    Hi Nazish,
    By default your application pages will inherit the masterpage currently applied to the site where your app is hosted, but to specify a custom master on a app page you have to set the "CustomMasterURL" property on your site.
    Next your application page needs to inherit from the "LayoutsPageBase" class and you need to specify your custom masterpage on your application page with "~masterurl/custom.master"
    Regards, Pieter
    MCPD | MCITP
    My Blog
    Please remember to click "Mark As Answer" if a post solves your problem or "Vote As Helpful" if it was useful.

  • How to set custom master page for sharepoint application page ?

    Hello,
    I need to apply custom master page for the custom application page I created for login purpose.
    Can anyone please let me know how to apply master page for custom application page ?
    Note : I need to set custom master page for application page at web application level.
    thanks,
    Dipti Chhatrapati

    Hi Dipti,
    You can use the same reference as ASP.NET
    Example
    "<%@ Page Language="C#" masterpagefile="../_catalogs/masterpage/minimal.master" title="teste" inherits="Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" meta:webpartpageexpansion="full"
    meta:progid="SharePoint.WebPartPage.Document" %>"
    You can use SharePoint Designer 2010
    http://www.microsoft.com/download/en/details.aspx?id=16573 to make the reference from you aspx page to you custom masterpage.
    When you are editing a aspx page you can go to ribbon "Style" and attach the custom Masterpage.
    André Lage Microsoft SharePoint, CRM Consultant
    Blog:http://aaclage.blogspot.com
    Codeplex:http://spupload.codeplex.com/http://simplecamlsearch.codeplex.com/

  • Custom Master page

      how to apply  custom master page site setting page in sharepoint2007 it's passible or not.

    Hello,
    Since layout page inherited from application.master page so your custom master page won't apply to settings page. You can use HHTPmodule to overwrite that master page:
    http://stephenkaye.blogspot.in/2008/03/how-to-customise-applicationmaster-file.html
    http://nikpatel.net/2009/12/20/moss-2007-implementing-the-custom-application-master-page-using-httpmodule/
    If you just want to change the color of links then you can also try with different theme.
    Hope it could help
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • Custom Master Page changes wont apply to few page layouts

    Dear All
    I'm having issue applying custom branding to SharePoint 2010 sites.. Branding works overall fine but it doesn't apply to few pages.
    For example if I click on Enterprise and Metadata Keyword Settings in Document library the changes are not applied. I notice it's a page called metadatacolsettings.aspx in layouts and I see it references application.master.. Similarly I see couple
    of other pages out of sync and all of them have application.master as Master Page..
    Any ideas why this could be happening.. Please let me know
    Thanks

    Hi,
    pls check below links
    There are a few things to consider.
    Have all page layouts / master pages been checked in and published / approved?
    Have you created a new page using the custom page layout?
    Are you creating or modifying this content?
    Keep in mind, the progression of rendering goes as follows:
    masterpages determine the ASP.NET structural layout.
    Page Layouts determine the SharePoint structural layout based on the masterpage ASP.NET structural layout.
    Your .aspx pages determine what content to display based on the Page Layout SharePoint structural layout.
     https://social.technet.microsoft.com/Forums/sharepoint/en-US/00d354cd-e49b-429f-8648-50251e1b39a0/changes-to-page-layout-not-refelected-when-using-custom-master-page?forum=sharepointcustomizationlegacy
    Please remember to click 'Mark as Answer' on the answer if it helps you

  • Custom master page applying on Publishing site template not in my site template?

    Hi,
    i have created a custom master page based on Publishing template Using Design manager (means converted html to aspx page) and then set all other control on the master page. now problem is master page applying only on Publishing site template not my site
    template. any one know why its happening, and how can resolve this issue?
    Thanks
    Mohammad

    Feature Stapling may be a solution - Please check -
    http://sharepointologic.blogspot.in/2013/04/branding-sharepoint-2013-my-sites-with.html
    http://www.codeproject.com/Articles/42129/Creating-branded-my-site-in-sharepoint
    Thanks
    Ganesh Jat [My Blog |
    LinkedIn | Twitter ]
    Please click 'Mark As Answer' if a post solves your problem or 'Vote As Helpful' if it was useful.

  • Create a blank page without custom master page applied,left navigation,top navigation

    hi,
     i am having a requirement where in i need to a  show a report- which is actually a  3rd party tool's custom web part -. this web part is a report which has lot of metadata. so customer doesnt want to see the custom master page
    or left navigation, top navigation, right nav in this page.
    is it possible to achieve a  blank  web part page that doesnt have custom master page applied- i mean  this page should not inherit the my custom master page- and just add the custom web part here.
    help is appreciated!
    Das

    Hi
    3 ways.
    1.use a blank page using sharepoint designer
    2. remove applied master page for an existing page
    3 use &isdlg=1 on your URL ( to hide the top of the master page elements )
    http://domain/path/page.aspx&isdlg=1
    Romeo Donca, Orange Romania (MCSE, MCITP, CCNA) Please Mark As Answer if my post solves your problem or Vote As Helpful if the post has been helpful for you.

  • Custom Master Page issue with Document Set Libraries

    Details: Publishing site using SharePoint 2013.  The SharePoint is on my company's servers.
    Have a custom Master page that has a navigation banner (built with HTML/CSS/javascript).  The site has it applied successfully to the "Site Master Page" but when I also apply it to the "System Master Page", the libraries that have
    Document Set type content do not show the files within.   We'd like to be successful in applying to the "System Master Page" as that allows the banner to show when an actual library is accessed.    Any suggestions, please?

    Thanks. I've been experimenting with this for a few days now, and there's lots I don't understand about why and such, but your process above works. That's a big load off me right now and I really appreciate it. I'm going to be able to survive the initial
    roll-out and implementation of the new site. Going forward, I've got lots to learn and find out, I've already heard that there's a desire to really redesign the master page for the site and subsites, way beyond the little CSS customization I did. Fun.
    If you've got a little time though, perhaps you can provide some explanation. If not, no problem.
    On step 6, when I do as you detail, click the System Master Page and reset all the subsites, it seems to work fine with my custom master page. If I do that with the Site Master Page settings, my custom page causes the redirect issue in the subsites again.
    This is whether I do the Site Master Page by itself, or in conjunction with the System Master Page settings. If I revert back to the Seattle master page in the Site Master Page settings and my custom pate in the System Master Page, the issue goes away again.
    It is completely messing with my head, trying to figure out why that would be, and this is all beside trying to figure out why adding the one little CSS reference to the Seattle master to create my master page breaks things (sometimes!).
    Just fyi, what I've ended up with for now is pulling my custom master page out of the system and using the Alternate CSS URL to add my custom CSS to the Seattle master page on the sites. As I thought about all this, I decided I didn't want to leave the breakable
    custom page out there for some unsuspecting site manager to accidentally pick and get everyone screaming about the broken sites.
    Thanks again,
    Steven

  • Create a custom Master Page in SharePoint Foundation 2013

    Hi,
    I am new to SharePoint foundation.
    I am trying to create a custom master page and save it as template, so that i can use it for all other sub sites. But i don't know where to start. Also i tries searching in Google, i got results for share point and not for share point foundation.
    So, Please give me a step by step procedure or a link to step by step procedure on how to create a master page, save it as template and use it for a sub site.
    Thanks in advance,
    Gowtham R

    Few points to note related to SharePoint Master page:
    You don't need to create master page template. If you deploy your master page in site collection level you can reuse the same master page in subsites without copying again and again, rather just by referencing
    You have not mentioned how you are going to deploy your master page. If you have any Visual Studio (VS) solution already, try to add your  master page in the VS solution and deploy your master page (and other branding components) as SharePoint WSP
    solution.
    Deploying master page will not activate the master page, you need to use some kind of 'Web Level Feature' to activate your branding - the feature will basically set the master page property of SharePoint site to your custom master page.
    Please follow the links below for steps by steps instructions (and you will find many just by googling 'sharepoint master page visual studio'):
    http://frederik.se/how-to-deploy-a-custom-master-page-in-sharepoint-2013-using-visual-studio/
    http://joshuaorimogunje.wordpress.com/2011/10/05/how-to-create-custom-master-page-for-sharepoint-2010-using-visual-studio-2010/
    http://blogs.msdn.com/b/bobgerman/archive/2011/01/31/packaging-master-pages-and-page-layouts-with-visual-studio-2010.aspx
    http://go.limeleap.com/community/bid/291931/Creating-a-Custom-SharePoint-Master-Page-with-jQuery-Using-Visual-Studio
    Thanks,
    Sohel Rana
    http://ranaictiu-technicalblog.blogspot.com

  • How do you apply a master page to multiple documents at the same time?

    How do you apply a master page to multiple documents at the same time?

    Hi friends,
    Thank you for trying to help me out.
    Let me explain it a bit to remove the ambiguity.
    I have 10 documents nested under a book. Each of these documents have 'n' number of pages. I want to apply my custom made master page "First" to the first page of all these 10 documents in one go. The remaining pages of the documents have to be in default "Right" master page format. How will I do it?
    I tried selecting all the documents and importing the formats from another document with the custom made "First" master page. The master page format is getting imported but the first page of all the documents still remain with the default "Right" master page format.
    I think now my question is more clear...

  • How can I create a custom feature, which will automatically take a custom master page while creating a site ?

    Hello ,
    I am new in Sharepoint development . I am trying to create a Sharepoint feature to Activate master page automatically while creating the site .Below mentioned code I am using to do this . 
    But When I am creating any site under site collection .It is not applying automatically . I have to manually Activate that feature . 
    SPSite site = properties.Feature.Parent as SPSite;
    SPWeb rootWeb = site.RootWeb;
    Uri masterUri = new Uri(rootWeb.Url + "/_catalogs/masterpage/mycustom.master");
    rootWeb.MasterUrl = masterUri.AbsolutePath;
    rootWeb.CustomMasterUrl = masterUri.AbsolutePath;
    rootWeb.Update();
    How Can I create a feature that can activate the master page at same time of site creation under Site collection ,Without any manual work .. 
    Thanks in Advance .. 

    Hi,
    You can associate master page during feature activation as follows:
    http://social.technet.microsoft.com/wiki/contents/articles/19933.sharepoint-2010-set-a-custom-master-page-during-feature-activation.aspx
    Then, you can use feature stapling to apply automatically on site creation:
    http://blogs.msdn.com/b/kunal_mukherjee/archive/2011/01/11/feature-stapling-in-sharepoint-2010.aspx
    Thanks,
    Avni Bhatt

  • Add Right Side Column and Web Parts to custom Master page in SharePoint Online

    Hello everyone, 
    I hope this is a simple question, however I was fighting the issue it presents for a while. I am in the process of customizing SharePoint Online Look-and-feel with a new layout.
    The site collection was created as a
    Team Site before I got involved with the project, and populated with numerous sub-sites and pages. I activated required
    publishing features, created html with corresponding styles and graphics, and used the Design Manager to convert the html file to the custom Master page. While SharePoint automatically assigned “ContentPlaceHolderMain” div area, I
    also used default Oslo page as example to copy sections of the code for dynamic components (left column and navigation, recent items, the ribbon, etc.) from it and placed them in my new master page, pointed all CSS references to
    my custom style sheets, etc. Everything works great, however I need to make one last addition -
    my task is to make changes to display web parts such as Calendar and Recent Documents in the right column in the Master page.
    My custom layout has a header, footer, main pan and two side columns. Most of the default master templates come with the LEFT column already embedded and populated with several placeholder
    to serve dynamic content (PlaceHolderLeftNavBarTop, PlaceHolderQuickLaunchTop, PlaceHolderLeftNavBarDataSource, PlaceHolderLeftActions, so on).
    My challenge is that I have the RIGHT side column as well, for which I don’t think the default placeholder exists. I need to add a small Calendar box and Recent Documents parts to it, so they
    display across the entire site governed by this master page.
    The issue is –
    even after activating Publishing features (enabled SharePoint Server Publishing Infrastructure under Site Collection Level, and SharePoint Server Publishing under the Site
    Level), there is no Snippet feature (usually available under the generic Publishing Site); this customization of the Team Site allows using Designer and apply custom templates, themes, so on, just like you would under the Publishing collection, but not the
    Snippet utility I could use as the solution to embed the web parts on the master page.
    Recreating the entire site under Publishing Collection is not an option due to the directions I was given, I am to use this existing one, and need to see if
    there is a workaround to either activate the Snippet feature or use another solution to display the web parts inside of the column in the Master page.
    If the only solution is to use Web Part Zone, what are the steps to add it AND populate it with the abovementioned apps?
    Can anyone suggest how to create a workaround and add this feature? The environment is role-based so both elements need to be dynamically rendered based on the user’s role and activities.
    I am more of a front end designer than developer, so if any custom coding and set up required, please kindly provide some basic steps, if possible?..
    I greatly appreciate any help and suggestions!
    Thank You!
    Jeff
    Jeff V.

    Updating your Master Page to also include a right rail should be sraight forward enough with a new div or divs in your master page and then the proper styles to make room for this column as well as position the column.
    I have not seen why you cannot find the snippet gallery link when previewing a HTML Master Page in the browser. Have you tried loading the snippet gallery by its url? As an example, for my tenant on SPO, I can load the Snippet Gallery for the olso.master
    with the following url:
    https://pixelmill.sharepoint.com/_layouts/15/ComponentConfigureControls.aspx?ComponentName=TopNavigationNoFlyoutWithStartNode&Url=%2F_catalogs%2Fmasterpage%2Foslo.master
    Change the domain to match yours as well as update the "Url" querystring var to point to your master page. See if that loads the snippet gallery.
    Eric Overfield - PixelMill -
    ericoverfield.com -
    @EricOverfield

Maybe you are looking for

  • How do I use search/find to search for a folder name

    I can successfully use Spotlight and Search in Finder and Mail to find files and emails based on their titles and contents, but how to I use the search functions to find a FOLDER by its name, that I have somehere in my nests of folders - so I can the

  • SanDisk 4GB Card Won't Mount

    If I connect the camera directly to my MAC and open iPhoto, it works just fine. The SD card however won't work on my SanDisk reader nor on my Lexar card reader. My CF card works on the Lexar reader though. How can I make this work? Thanks!

  • Multitenancy and Entity Manager

    We are using JPA with eclipse link. We have extensive JPA queries. Our code is in production for a while. Now we have  a business use case, to support multitenancy. We will be using the Oracle Pluggable Database mechanism where each client will have

  • Column's Right Alignment goes out with CR in format Mask like NNN,NN0.00CR

    I am working in Reports 6i. For a numeric calculated column, I give format mask NNNN,NNN,NNN,NN0.00CR. Due to CR, right alignment of the column goes out. That is rows for which CR is NOT printer are also aligned at right. A blank space should be left

  • PLSQLAssociativeArray - ArraybindSize

    Hello all, Does anybody know the maximum size of an output parameter for ArrayBindSize when accessing a table of varchar2. And if so is their a way to set the limit? Right now I can go to a maximium of 2000 characters. thanks, Dhaval