Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a branding solution consisting of one feature to deploy a custom master to the site collection. A web scoped feature exists in a separate solution that when activated sets the custom master as the MasterUrl and CustomMasterUrl. I have separated this into its own solution as we have several branding packages, each having a master that shares the same name.

The problem I have is that if the master page does not exist when the web scoped feature is activated, the whole site blows up (understandably).

What I want is to verify that this custom master page exists. So far I've tried setting up an HTTP Request / Response and verify that the response is OK before setting the master URL, but it hasn't worked. I'm starting to wish I just dealt with having redundant code by having this web scoped feature as a part of each branding package - at least then I can set up a feature activation dependency.

So how can I verify that the master page exists in the expected location before I apply it?

share|improve this question

2 Answers 2

So in the feature receiver where you set the MasterUrl and CustomMasterUrl properties, just check to see if the feature that deployed the custom master to the site collection exists.

Here's an example on how to check for the existence of a feature in a site collection:

http://www.davidyardy.com/blog/post/2011/01/28/Feature-Exists-(Activated-on-SPSite).aspx

share|improve this answer

If you want to check for the existance of the masterpage file, I would do something like this:

bool fileExists = web.GetFile(newMasterUrl).Exists;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.