Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

How to check page is homepage/default page programmatically in C# sharepoint 2010

share|improve this question

3 Answers 3

SPContext.Current.ContextPageInfo.IsWebWelcomePage

share|improve this answer

To know if a web page is the default page of a SharePoint web site (or any folder) in c# you can use the SPFolder.WelcomePage property. This property return a URL for the default page so you can compare it with the URL of the page you want to test.

Example to test if a page is default for a SharePoint site:

// After you get the SPWeb object...
string defaultPageUrl = web.RootFolder.WelcomePage;
if(defaultPageUrl == <Test Page Url>)
{
  <Test Page Url> is the default page.
}
share|improve this answer
    
I was researching myself the answer, so I would like to complete yours: string defaultPageUrl = Microsoft.SharePoint.Utilities.SPUtility.ConcatUrls(web.ServerRelativeUrl,web.Ro‌​otFolder.WelcomePage); and <Test Page Url> should be this.Page.Request.Url.AbsolutePath. Then the comparison will work indeed. :) –  Norbert Dec 6 '12 at 10:54

You can set a page as home page through sharepoint designer but if you need to check it is home page or not check this link:

https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spcontextpageinfo.iswebwelcomepage.aspx

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.