How to Set Welcome Page Programmatically in SharePoint?
By default, SharePoint uses "default.aspx" page as the welcome page (or Home page) in SharePoint 2007 and "SitePages/Home.aspx" in SharePoint 2010. It uses Pages/Home.aspx when publishing feature is enabled under MOSS 2007.
If you want to change Home Page: SharePoint provides users an interface to set the welcome page once Publishing feature is enabled. (By going to Site actions >> Site Settings >> Welcome Page)
and specify the welcome page.
What if You don't want to enable the publishing feature, but want to change the Welcome page? Just hit this URL in browser:
Want to do it Programmatically? Yes, We can set welcome page in SharePoint 2010 programmatically with Object Model. Here is how:
Change welcome page programmatically Using C# Object Model:
Set Welcome Page in SharePoint Using PowerShell:
If you want to change Home Page: SharePoint provides users an interface to set the welcome page once Publishing feature is enabled. (By going to Site actions >> Site Settings >> Welcome Page)
and specify the welcome page.
What if You don't want to enable the publishing feature, but want to change the Welcome page? Just hit this URL in browser:
http://Sharepoint-site-URL/_layouts/AreaWelcomePage.aspx ,change the Sharepoint-site-URL accordingly.
Want to do it Programmatically? Yes, We can set welcome page in SharePoint 2010 programmatically with Object Model. Here is how:
Change welcome page programmatically Using C# Object Model:
using (SPSite site = new SPSite("http://sharepoint.com")) { using (SPWeb web = site.RootWeb) { SPFolder rootFolder = web.RootFolder; rootFolder.WelcomePage = "Pages/HomePage.aspx"; rootFolder.Update(); } }
Set Welcome Page in SharePoint Using PowerShell:
$SiteUrl = "http://sharepoint.com" $Site = Get-SPWeb -identity $SiteUrl $RootFolder = $Site.RootFolder; $RootFolder.WelcomePage = "SitePages/HomePage.aspx"; $RootFolder.Update(); $Site.Dispose()
No comments:
Please Login and comment to get your questions answered!