SharePoint: How to Change The Default Welcome Page on a Site

If you want to programmatically set a site’s default welcome page you can write the following code to redirect it to another page within the site.

The url path must relative and you MUST create another SPFolder object to reference the RootFolder and perform your update, or else it won’t work:

using Microsoft.SharePoint;

namespace SharePointConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var spSite = new SPSite("http://spdev/test"))
            {
                using (var spWeb = spSite.OpenWeb())
                {
                    var rootFolder = spWeb.RootFolder;
                    rootFolder.WelcomePage = "Lists/Events/AllItems.aspx";
                    rootFolder.Update();
                }
            }
        }
    }
}
Shares