I created a custom site definition in SharePoint 2010 declarative using ONET.xml. As Part of the Site Definition I created a page from page layout using “module”
element as a feature and embedded this feature in Onet.xml “WebFeatures”
section.
Now what I am trying to achieve is, as soon as the site collection is created from this custom Site Definition the above page created using “module” element must be set as homepage and to create subsites programmatically, But I am stuck here.
Basically what I did was I created a custom “WebProvisioned”
event receiver and wrote code to set the newly created page as homepage for the root web of the site collection. I made this event receiver as site scoped. If I navigate to the “Pages” library I can see my new page, but it’s not set as homepage\welcome page. I deactivated and reactivated the event receiver multiple times but still it is not set as the welcome page. Below is my code.
public override void WebProvisioned(SPWebEventProperties properties)
{
base.WebProvisioned(properties);
SPSite site = properties.Web.Site;
SPWeb web = site.RootWeb;
SPFolder rootFolder = web.RootFolder;
rootFolder.WelcomePage = "pages/myHome.aspx";
rootFolder.Update();
web.Update();
}
Any idea what’s happening? And what are my other options to achieve the same thing?
Thanks