C# – How Do I Get The Default/Welcome Page Of A SharePoint 2010 Site

csharepoint

I'm new to SharePoint 2010 coding web parts. I'm trying to figure out how to get the landing page of a SharePoint site given the URL.

Ex. I give the function http://www.yahoo.com and I get http://www.yahoo.com/pages/default.aspx .

Here's the function so far:

private string GetSPSiteUrl(string u) {
    var siteurl = string.Empty;

    using (SPSite site = new SPSite(u)) {
        using (SPWeb web = site.OpenWeb()) {
            siteurl = web.Url;
        }
    }

    return siteurl;
}

The function just returns what I give it now which is no use.

Any help would be great. Thanks!

Best Answer

A simpler approach without having to click through.

This gives you the direct "WelcomePage" url:

web.RootFolder.WelcomePage

If you need the actual item:

SPListItem welcomePage = web.GetFile(web.RootFolder.WelcomePage).Item;
Related Topic