Has anyone had the error Invalid URL when setting the masterpage programmatically?
Using this code in a feature receiver (the feature provisions the masterpage to the gallery, that works fine)
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSite oSite = (SPSite)properties.Feature.Parent;
using (SPWeb oWeb = oSite.OpenWeb())
{
oWeb.CustomMasterUrl = oWeb.Url + "/_catalogs/masterpage/GIS.CZEN.MIST.master";
oWeb.AllProperties["__InheritsCustomMasterUrl"] = "True";
oWeb.Update();
}
}
If I activate this feature on site http://<server>/<path>/<site>/ then I'll get the error:
Invalid URL: http://<server>/<path>/<site>/_catalogs/masterpage/MyMaster.master
This happens with Team Sites as well as Publishing Sites, in SharePoint Server 2007.
EDIT: All suggestions are valid, but the real fix for me was using oWeb.ServerRelativeUrl instead of oWeb.Url.
