Dela via


How to get the default landing page of a SharePoint site ?

If you want to get the default page of a publishing template based sites (or any sites which are enabled publishing features), then can directly get it from the PublishingWeb.DefaultPage Property. But, there is no a direct property or method to get the default page of a non-publishing based sites, but it is possible in the following way.

    1: using (SPSite oSite = new SPSite("https://sowmyans1"))
    2:  
    3:       {
    4:         using (SPWeb oWeb = oSite.OpenWeb())
    5:         {
    6:             object oFolderObject = oWeb.GetFileOrFolderObject("https://sowmyans1/");
    7:          // below line worked fine for me in SPS 2010, but not in MOSS (non publishing)
    8:          // string strWelcomePage = ((Microsoft.SharePoint.SPFolder)(oFolderObject)).WelcomePage;                    
    9:  
   10:          // below line worked fine for me in both SPS 2010 and MOSS
   11:             SPFileCollection oFiles = ((Microsoft.SharePoint.SPFolder)(oFolderObject)).Files; 
   12:             string strFile = oFiles[0].ServerRelativeUrl; 
   13:         }
   14:   }

For Publishing sites : https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.publishing.publishingweb.defaultpage.aspx