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
    
check means Check Out/ Check In ? –  Arsalan Adam Khatri Dec 6 '12 at 9:27
add comment

1 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
add comment

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.