SharePoint 2010: Three ways to change Home Page
From Browser
Property bag Feature
SharePoint Object model
- Open SharePoint Site
- Navigate to page you are going set as Home page.
- Click to the home page
- Click Make Home page from ribbon under Page Actions Group.
- Open visual Studio 2010.
- Create new empty SharePoint Project “SetHomePage”.
- Add new empty element “HomePagePropertyBag”
- Copy the relative page URL that you want to set as home page.
- Write the following lines your Properbag features.
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<PropertyBag Url="" ParentType="Folder" RootWebOnly="false">
<Property Name="vti_welcomePage" Type="string"
Value="lib/TestWelcomePage.aspx"></Property>
</PropertyBag>
</Elements>
SharePoint Object model
- Open visual Studio 2010.
- Create New Empty SharePoint Project “SetHomePageByCode”
- Add new feature
- Add new feature recover.
- On feature activation write the following lines of code.
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWeb _Web=null;
if (properties.Feature.Parent is SPWeb)
{
_Web = (SPWeb)properties.Feature.Parent;
}
else if (properties.Feature.Parent is SPSite)
{
_Web = ((SPSite)properties.Feature.Parent).RootWeb;
}
if (_Web != null)
{
SPFolder _rootFolder = _Web.RootFolder;
_rootFolder.WelcomePage = "lib/TestWelcomePage.aspx";
_rootFolder.Update();
}
}
Comments
Post a Comment