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
NelsonPosted Nov 20, 2009, 1:11 PM
So, If someday you need to change a master page with a click, this code works fine.
Nelson.
Sam HobbsPosted Nov 20, 2009, 2:41 AM
NelsonPosted Nov 17, 2009, 5:08 PM
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 HobbsPosted Nov 17, 2009, 11:29 AM
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.