Pages

Search This Blog

Wednesday, February 22, 2012

Assign default page of Publishing site to custom page during site provisioning

In my previous post, I have highlighted how to create pages in Pages library using CAML when a site is being provisioned.
We had created Home.aspx custom page.
 

Requirement:
We need to set Home.aspx as the default welcome page of the site, when the site is being provisioned.

Solution:
We can achieve this by putting a piece of code in the feature receiver.


//Get the Publishing Web object
PublishingWeb objPublishingWeb = PublishingWeb.GetPublishingWeb(web);
//Get the Home.aspx file from Pages library
SPFile objHomePageFile = web.GetFile(objPublishingWeb.PagesListName + "/Home.aspx");            

//Set default page of publishing web
objPublishingWeb.DefaultPage = objHomePageFile;
objPublishingWeb.Update();
web.Update();
  
If we browse the site now, Home.aspx opens up as the default page.

No comments:

Post a Comment