SharePoint 2010: Three ways to change Home Page

From Browser 

  • 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.

Property bag Feature
  • 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();
}
}
 

Popular posts from this blog

SharePoint RPC Protocols Examples Using OWSSVR.DLL

STS CryptographicException Error : Key set does not exist

SharePoint 2016 JavaScript framework