Answered by:
Programmatically find home page Url of SPWeb

Question
-
Hello All,
How I can programmatically find the home page of SPWeb ? it can be team, publishing or wiki or any kind of site.
ShailWednesday, December 8, 2010 12:21 PM
Answers
-
Try this:
string strHomePage = "";
if (PublishingWeb.IsPublishingWeb(web))
{
strHomePage = PublishingWeb.GetPublishingWeb(web).DefaultPage;
}else {
strHomePage = web.RootFolder.WelcomePage;
}
regards
Martin Hatch
MCPD .Net Web Development
MCTS WSS 3.0 | MOSS 2007
Visit my Blog - www.martinhatch.com- Marked as answer by Shailendra Singh ChauhanMicrosoft employee Wednesday, December 15, 2010 9:40 PM
Wednesday, December 8, 2010 12:35 PM -
Hi, Shail
After some testing, only “basic search” site is not a “publishing site”, and the web.RootFolder.WelcomePage property is “”, Enterprise Search Center and Search Center could work as expected.
For some specific page, you could consider using hard code as a walkaround.
Hope this can help.
Best Regards,
Aaron
- Marked as answer by Shailendra Singh ChauhanMicrosoft employee Wednesday, December 15, 2010 9:40 PM
Wednesday, December 15, 2010 7:51 AM
All replies
-
Try this:
string strHomePage = "";
if (PublishingWeb.IsPublishingWeb(web))
{
strHomePage = PublishingWeb.GetPublishingWeb(web).DefaultPage;
}else {
strHomePage = web.RootFolder.WelcomePage;
}
regards
Martin Hatch
MCPD .Net Web Development
MCTS WSS 3.0 | MOSS 2007
Visit my Blog - www.martinhatch.com- Marked as answer by Shailendra Singh ChauhanMicrosoft employee Wednesday, December 15, 2010 9:40 PM
Wednesday, December 8, 2010 12:35 PM -
Try this:
string strHomePage = "";
if ( PublishingWeb . IsPublishingWeb ( web ))
{
strHomePage = PublishingWeb . GetPublishingWeb ( web ) . DefaultPage ;
}else {
strHomePage = web.RootFolder.WelcomePage ;
}
regards
Martin Hatch
MCPD .Net Web Development
MCTS WSS 3.0 | MOSS 2007
Visit my Blog - www.martinhatch.com
Will that work for any kind of site ? ( using any kind of site template, including custom site templates )
ShailWednesday, December 8, 2010 2:34 PM -
Yeh should do.
Publishing sites work slightly different to "other" sites (as they use Page Layouts and store values using the "Welcome Page" property, which you can set from Site Settings).
Other sites (such as Team Sites / Blank Sites .. and really any non-publishing site) uses the WelcomePage property of the Root Folder.
In order to set this I believe there is also a property in the SPWeb.AllProperties hash-table .. although the exact name of the value escapes me right this minute.
regards
Martin Hatch
MCPD .Net Web Development
MCTS WSS 3.0 | MOSS 2007
Visit my Blog - www.martinhatch.comWednesday, December 8, 2010 2:36 PM -
Ok,
So in case if somebody set some other page as home page ( by using SharePoint designer or any other means ), my code will give me correct page ?
ShailWednesday, December 8, 2010 2:51 PM -
Hello,
I have wriitten code for this and its working fine, But for some site like search site, its not working. Any idea why ?
ShailFriday, December 10, 2010 1:45 PM -
Hi, Shail
After some testing, only “basic search” site is not a “publishing site”, and the web.RootFolder.WelcomePage property is “”, Enterprise Search Center and Search Center could work as expected.
For some specific page, you could consider using hard code as a walkaround.
Hope this can help.
Best Regards,
Aaron
- Marked as answer by Shailendra Singh ChauhanMicrosoft employee Wednesday, December 15, 2010 9:40 PM
Wednesday, December 15, 2010 7:51 AM -
How can I use de Search Center to do that?Tuesday, April 19, 2016 8:01 PM