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.


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

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;
If we browse the site now, Home.aspx opens up as the default page.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s