Search This Blog

Sunday, April 24, 2011

Programmatically change the Welcome / Default page of a Sharepoint Publishing Web

Sometimes we have a requirement like on feature activation or deactivation we have to change the Welcome Page(Default Page) of the publishing site.
Below is the code snippet with the help of which we can change the Welcome Page:
public override void FeatureActivated(SPFeatureReceiverProperties properties)
            using (SPSite objSiteProperty = (SPSite)properties.Feature.Parent)
                using (SPWeb objSPWeb = objSiteProperty.OpenWeb())
                    PublishingWeb objPublishingWeb = PublishingWeb.GetPublishingWeb(objSPWeb);
                    SPFile objHomePageFile = objSPWeb.GetFile("Pages/Test.aspx");
                    objPublishingWeb.DefaultPage = objHomePageFile;

And in the same way on Feature Deactivation we can change the Welcome Page again.

1 comment:

  1. I am getting issue
    Could not load type 'Microsoft.SharePoint.SPReusableAcl' from assembly 'Microsoft.SharePoint, Version=14.900.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'.