Automatically Setting the Masterpage in Sharepoint 2013

I am trying to install our custom masterpage (and supporting files) as a feature which would automatically turn on and set the default masterpage to our custom one.
When deploying in VS2012, it works fine. The feature is installed & activated at the site collection level and the default masterpage is successfully changed.
But when I publish the solution and install the WSP via Solution Management in Central Administration, it doesn't work. The feature gets installed & activated at the site collection level BUT it doesn't set the masterpage to our default.
If i then turn the feature off and back on again the default masterpage is correctly set to our custom masterpage.
Our requirement is to have everything done automatically so having not having to turn the feature off and back on is something we need.
I'd appreciate any tips or help to get this working.
using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using System.Linq;
namespace our_masterpage.Features.Activate.Custom.Master
/// <summary>
/// This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade.
/// </summary>
/// <remarks>
/// The GUID attached to this class may be used during packaging and should not be modified.
/// </remarks>
[Guid("fca75088-7182-4727-853a-76e82fdfc7a1")]
public class ActivateCustomEventReceiver : SPFeatureReceiver
{/// Activating the feature
public override void FeatureActivated(SPFeatureReceiverProperties properties)
SPSite site = properties.Feature.Parent as SPSite;
if (site != null)
SPWeb topLevelSite = site.RootWeb;
// Calculate relative path to site from Web Application root.
string webAppRelativePath = topLevelSite.ServerRelativeUrl;
if (!webAppRelativePath.EndsWith("/"))
webAppRelativePath += "/";
// Activate publishing infrastructure
site.Features.Add(new Guid("f6924d36-2fa8-4f0b-b16d-06b7250180fa"), true);
// Enumerate through each site and apply branding.
foreach (SPWeb web in site.AllWebs)
// Activate the publishing feature for all webs.
web.Features.Add(new Guid("94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb"), true);
web.MasterUrl = webAppRelativePath + "_catalogs/masterpage/our-custom-masterpage.master";
web.CustomMasterUrl = webAppRelativePath + "_catalogs/masterpage/our-custom-masterpage.master";
web.Update();
/// Deactivating the feature
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
SPSite siteCollection = properties.Feature.Parent as SPSite;
if (siteCollection != null)
SPWeb topLevelSite = siteCollection.RootWeb;
// Calculate relative path to site from Web Application root.
string webAppRelativePath = topLevelSite.ServerRelativeUrl;
if (!webAppRelativePath.EndsWith("/"))
webAppRelativePath += "/";
// Enumerate through each site and apply branding.
foreach (SPWeb site in siteCollection.AllWebs)
site.MasterUrl = webAppRelativePath + "_catalogs/masterpage/seattle.master";
site.CustomMasterUrl = webAppRelativePath + "_catalogs/masterpage/seattle.master";
site.SiteLogoUrl = string.Empty;
site.Update();

The question was answered in another forum,..
Second, your code fails because it assumes that the feature activation happens while on a particular SharePoint web site:
SPSite site = properties.Feature.Parent as SPSite;
If activating via PowerShell you will not get a valid SPSite object via the code above, while it works just fine if running via a Web browser UI on the site collection feature page.
Disabling the auto-activation and run the corresponding PowerShell code to activate the feature once the WSP has been installed and deployed should fix your problem.
Do this worked like a charm.

Similar Messages

  • Security Groups for the alerts in SharePoint 2013?

    By default Microsoft has blocked to add Security Groups for the alerts in SharePoint 2013. It can be enabled but need to change the SharePoint System page setting with the help
    of below link:
    http://thesharepointfarm.com/2013/10/setting-sharepoint-alerts-on-active-directory-security-groups/
    So my query is if I change the page setting then in future if any SharePoint updates/ hotfixes deploy in system so will it cause a problem??

    I would wait as this is not a supported workaround (although it does work).
    Trevor Seward
    Follow or contact me at...
    &nbsp&nbsp
    This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

  • Can i automatically set the timestamp of a file based on part of its filename?

    I have a bunch of files (approx. 500) with the same name pattern, that is : name_CreationDate.pdf. For instance: invoice015_2013_06_25.pdf or invitation035_2012_11_30.pdf. The last 10 digits are always the creation date. The original timestamps of the files have been messed up by a batch application which set them all to the same day; therefore they mean nothing anymore.
    Is there a way to automatically set the timestamp (for instance the "Creation Date" one) to the date indicated in the filename? I was thinking of Automator or some kind of shareware/freeware. Does anyone of you have an idea about this? Ideally as a batch rather than individually.
    Thanks,

    Thank you for your script. I made a test based on your script:
    a) I copied a PDF file on my desktop and named it "URSAFF 1er trim 2012_1998_09_19.pdf". The date component I want to set ultimately is therefore 1998_09_19.
    b) I created a service in Automator and pasted your script in a "Run a Shell Script" command. I added the Get Specified Finder Items at the beginning to be able to test the script on the file from Automator. (See screen shot of Automator below)
    c) The script appears to run successfully but I don't see a change in the timestamps of the file after I display Get Info from the Finder. (See screen shot of Get Info after I run the shell script)
    I wonder if my Region settings (I am based in France) do not interfere with the date/time string layout compatible with touch in your script. Just in case, I have added a capture of these settings.

  • Issue in Custom Blog site definition based on SharePoint 2010 blog site definition after migrating the sites to SharePoint 2013 and site collection upgrade

    I have created a custom blog site definition using SharePoint 2010 blog site definition with Configuration ID 31 in onet.xml (new value). This was working fine for SharePoint 2010.
    We created new SharePoint 2013 farm and deployed the all Custom solutions in
    14/15 folders. After migrating the sites to SharePoint 2013 using Content DB approach, site created previously using my custom definition are working fine.
    But after running site collection upgrade these sites stop working. When I post a comment then comments not getting listed on post detail page. However comments are getting added to Comments List but
    PostTitle column  of Comment is not getting populated.
    Also, when we create a new site in SharePoint 2013 using my custom blog template then that is also not getting provisioned.  default.aspx and look-up between post and comment list are not working.
    If any one has faced such issue then please share your findings and any solution to fix this.
    Thanks in Advance :)

    Hi ,
    According to your description, my understanding is that the blog based on custom blog site definition didn’t work correctly after migrating custom blog site definition to SharePoint 2013.
    If you customized the Onet.xml file in a previous version's site definition, you should modify some sections in the file to work in the current version, like  <BaseTypes> and  <ListTemplate>  etc. More information, please refer
    to the link below:
    http://msdn.microsoft.com/en-us/library/office/aa543837(v=office.14).aspx
    For that the PostTitle column  of Comment is not getting populated, please try to modify the view, then compare the result.
    I hope this helps.
    Thanks,
    Wendy
    Wendy Li
    TechNet Community Support

  • How do I make Mail automatically set the reciepient of an E-Mail as the replying E-Mail-Adress

    Hi!
    I have an @me.com iCloud E-Mail-Adress with 2 Aliases
    I'm using one of them for students of my tutorial at the university, so that they can contact me without knowing my actual email-adress.
    so when someone of them sends me a message to this tutorial-alias and a write an answer, i always have to set the replying email adress
    from my actual @me.com to the tutorial-alias.
    I often forget to do this, so in the replying email people see my actual one instead of the alias, answer on it again, and everybody starts using both.
    I want to prevent this, so ist there a way to automatically set the replying adress to the one the former email im replying on was sent to?
    Regards
    DaNylz

    Mail Preferences:
    It works with accounts; I've never tried it with aliases but you may be lucky. Presumably from what you say they already appear in the drop-down menu when composing.

  • What "apps" are available in the "on-premise" Sharepoint 2013 Server evaluation edition?

    Hello Community
        Is Yammer available in the "on-premise" SharePoint 2013 Server evaluation edition?
        Thank you
        Shabeaut

    If you can see a option to setup Yammer, then you can do the setup.
    Refer here - http://technet.microsoft.com/en-us/library/dn270535%28v=office.15%29.aspx
    Thanks, Ashish | Please mark a post helpful/answer if it is helpful or answer your query.

  • Automatically set the Black and the White points in Aperture?

    Jasoninajeep, in this thread, refers to this Aperture Export article, which includes the helpful hint that holding "{Option}" while clicking the auto-luminance button in the Curves brick will cause Aperture to set the Black and the White points without making any other changes.
    Is there any other way to automatically set the Black and the White points in Aperture?
    Thanks.

    Hi BBurgess!
    Unfortunately, it sounds like you may have a service issue on your hands.  While our QuickStart guide provides details on installing the cartridges in their respective slots, putting those catridges in the wrong position may cause an internal issue with the Canon PiXMA MG3222.  
    We recommend contacting our Technical Support group directly via this Contact Us link.  Our Technical Support group can provide you with all available service options.
    Thanks!

  • Automatically set the stroke color as fill color

    Hello all,
    I have a file with two squares with red and blue fill colors respectively and transparent surrounding strokes. I'm trying to find a way to automatically set the stroke color of each square to the respective fill color.
    Is there an Illustrator script somewhere that would achieve that? I am not aware of an internal Illustrator command for this purpose.
    Thank you

    I'm not a scripting guy at all, but getting an object's fill color and applying it elsewhere sounds like it should be scriptable. You should post the question in the AI Scripting Forum.
    The hitch I see here is your assertion that your objects have "transparent surrounding strokes." I could be wrong, but I believe there is actually no such thing in Illustrator. Through some simple experimenting, I conclude that an object's stroke set to "no color" by choosing the blank swatch actually becomes a stroke of undetermined, or perhaps zero, weight.
    Take an object with a stroke color and weight and set its stroke to no color. The weight goes away as well. One can't exist without the other, and vice-versa, with repect to stroke weight and color. Now enter a weight for that colorless stroke, and it again receives color; defaulting to black regardless of what it may have been previously.
    Similarly, if you assign a color where there is no weight, a 1-point weight appears by default.
    I'm not sure how/if that plays into your plans, but I just thought I'd ramble on about it here in case it's something you hadn't considered.

  • What's the difference between SharePoint 2013 and Office 365 Team Sites?

    Hi there,
    What are the differences between SharePoint 2013 and Office 365 Team Sites?
    If I would like to develop a professional corporate website with SharePoint technology (because the company allready uses Office 365), do you recommend using SharePoint 2013 (in the cloud) or Office 365 Team Sites? And why?
    Thank you very much!

    You cannot make SPO Team Sites anonymous-enabled, therefor they're a moot point for a public website.
    While slightly out of date, take a look at this:
    http://nikpatel.net/2013/01/17/new-sharepoint-2013-wcm-features-are-not-available-in-sharepoint-online-2013/
    http://technet.microsoft.com/en-us/library/sharepoint-online-content-service-description.aspx
    Trevor Seward
    Follow or contact me at...
    &nbsp&nbsp
    This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

  • Setting up SMTPSendGrid for SharePoint 2013

    I have set up a SharePoint 2013 VM in Windows Azure and would like to know how to configure my SharePoint server installation to send e-mails using SMTPSendGrid since SMTPSendGrid requires authentication credentials and SharePoint does not support providing
    authenticated credentials for sending outgoing e-mail messages.
    I read something about configuring the SMTP Send E-mail settings in IIS 7 and above but I am not sure if it is sufficient to configure those settings in order to get the e-mails to send out correctly.
    Please advise.
    Thanks.

    Correct, you would need to install IIS SMTP, configure SharePoint to send to that, the configure IIS SMTP to relay to SendGrid. This is similar to
    http://blogs.technet.com/b/yashgoel-msft/archive/2012/10/26/configuring-outgoing-email-settings-in-sharepoint-with-gmail-smtp.aspx
    Trevor Seward
    Follow or contact me at...
    &nbsp&nbsp
    This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

  • Install Web Part Using Set up file for Sharepoint 2013

    HI,
        How to install web part to sharepoint 2013 using a setup wizard.
    Suppose i have webpart for some data manipulation process so i need to make a set up for install this web part in any sharepoint system is it possible , programmatically install web part is possible any one have code regarding this or can you suggest me how
    to do this ?
    Thanks & Regards
    SUJIL KUMAR t
    Software developer

    Hi Sujilkumar,
    According to your description, my understanding is that you want to install web part wsp using install wizard.
    In SharePoint, there is no set up wizard to install the web part. If you want to install your custom web part, you can use PowerShell Commands. Before you can deploy a solution package, you need to add it to the solution database of a SharePoint
    Server farm like below:
    add-spsolution c:\yourwsp.wsp
    Then you can install the solution like below:
    Install-SPSolution -Identity <SolutionName> -WebApplication <URLname>
    Here are some detailed articles for your reference:
    how to add a wsp webpart
    Deploy solution packages
    Best Regards
    Zhengyu Guo
    TechNet Community Support

  • Set up HA in SharePoint 2013 with NLB

    Hi All,
    We have 2 database servers in cluster and 2 application servers in a single SharePoint farm.
    We need to configure HA along with NLB for SharePoint 2013 in our environment.
    Please help.. !!

    First off, you need to decide what your recovery objectives are for HA so you'll know which technology to use. For the database side, you mentioned 2 database servers in a cluster. Is this configured as a 2-node SQL Server failover clustered instance or
    an Availability group with 2 replicas? These 2 configurations meet your HA requirement but are implemented differently with SharePoint accessing them differently. For the SharePoint web and application servers, you can use a software NLB like Windows NLB or
    a hardware NLB like Cisco or F5. You simply add servers to the farm and move service applications and roles around those servers. This really depends on what service applications you want to run and what your goals are
    Edwin Sarmiento SQL Server MVP | Microsoft Certified Master
    Blog |
    Twitter | LinkedIn
    SQL Server High Availability and Disaster Recover Deep Dive Course

  • Is there a way to make it automatically set the ouputs of new tracks to Bus 5? (or something other than Stereo Out?)

    When I add a new track, it is automatically set to Stereo Out, is there a way to make it automatically set to Bus 5?  I use a mix that sends everything through busses and every time I add a track it seems I have to adjust this.
    Thanks

    ...and/or setup one or more tracks the way you want.. and then create/save a template and load that when you want to start a new project...
    You can even have Logic (via it's Startup preferences) autoload that template every time you start a new project... by choosing your template as the default one.
    See this page in the User Guide for more info

  • Need to show the images in calculated column based on the condition in sharepoint 2013.

    Hi ,
    I'm working in sharepoint 2013, In this i want to show an image in calculated column based on the condition, but image is not showing .
    In sharepoint 2010 its working with help of javascript in content editor on the same page. Same thing i tried in SP 2013. but doesn't work.
    Could any one please give proper solution for this?
    Thanks in advance.
    by,
    Siva.

    Hi please provide the JS you have used in the content editor as well as the calculation for the column so we can better understand what's maybe differs?
    Blog: chrisstahl.wordpress.com Twitter:
    @Cstahl

  • Setting up multi-tier SharePoint 2013

    Hello Friends,
    I would like to set-up multi-tier farm on my VM. I have installed 2 Windows server partitions. Requirement is to set-up SQL server on 1st VM and 2nd VM will act as App server and WFE.
    I'm new to this installation stuff, so can you all guide me how to proceed further regarding services to be activated and connecting SQL on 1st VM with CA on 2nd VM

    Hi,
    Please check those links
    Tutorial
    https://www.youtube.com/watch?v=_CL-ttdk5cU
    already Built trial environment
    http://www.matthewjbailey.com/sharepoint-2013-dev-environment/
    Kind Regards,
    John Naguib
    Technical Consultant/Architect
    MCITP, MCPD, MCTS, MCT, TOGAF 9 Foundation
    Please remember to mark your question as answered if this solves your problem

Maybe you are looking for