Hi there,
I am trying to change the master page of a webapp in SS I tried this code:
public void mSetMasterPage(string sUrlSite, string sWebName)
{
using (SPSite oSiteCollection = new SPSite(sUrlSite))
{
SPWeb myWebSite = oSiteCollection.OpenWeb(sWebName);
myWebSite.MasterUrl = "/_layouts/BlackBand.Master";
myWebSite.CustomMasterUrl = "/_layouts/BlackBand.Master";
myWebSite.Update();
}
}
And in theory this works, but when I open the webapp it only says "Error" and I supose that I am missingo something, but I do not know what, could anyone give me a hand???
Thank you very much for any answer,
Nelson
Loading

Sam HobbsRank #107 · 20.5K reputationPosted Nov 17, 2009, 6:29 AM EST
You should use try/catch blocks. Your program might be getting an error that is ignored and then leads to a more serious error. Don't write code that ignores errors then ask for help solving vague problems.
Even if you don't modify the program, you can use a breakpoint and single-stepping to determine what line it is that is getting the error. When you do, watch each line for possible errors that are not caught by your program.
Nelson6 reputationPosted Nov 17, 2009, 12:08 PM EST
Well, I found that my code is ok, it works, but now I found another small problem, Now i found that I have to add my new custom master page to the site collection, but I do not find/know how to do that, do you know what property should I affect to achieve this?
Thank you very much for your answer.
Nelson
Sam HobbsRank #107 · 20.5K reputationPosted Nov 19, 2009, 9:41 PM EST
Nelson6 reputationPosted Nov 20, 2009, 8:11 AM EST
So, If someday you need to change a master page with a click, this code works fine.
Nelson.