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?

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:



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

bool fileExists = web.GetFile(newMasterUrl).Exists;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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