How to do the following but with code? my page name is actnow.aspx

click the "Site Actions" menu bar, select "Site Settings" and then click on "Modify All Site Settings". Under the "Look and Feel" column is a link called "Welcome Page".

  • PublishingPage publishingPage = pubWeb.AddPublishingPage("sharepointtest/justanothersite/Pages/new-default.aspx", pageLayout); publishingPage.Update(); pubWeb.DefaultPage = publishingPage.ListItem.File; pubWeb.Update(); const string checkInComment = "Initial Check In"; publishingPage.CheckIn(checkInComment); SPFile pageFile = publishingPage.ListItem.File; pageFile.Publish(checkInComment); pageFile.Approve(checkInComment); pageFile.MoveTo(file.ListItemAllFields.ParentList.RootFolder.Url + "/default.aspx", true); pageFile.Update(); }
    – Roxanne
    Commented May 9, 2011 at 19:48
  • 1
    Is this the answer to your question or an edit? This code doesn't belong in a comment...
    – Kit Menke
    Commented May 9, 2011 at 20:14

5 Answers 5


What you want is PublishingWeb.DefaultPage - it has to point to an SPFile represented by a list item in your Pages library.


Combine this with Lori's suggestion for doing it in PowerShell.


There is a powershell script for this here: http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010setup/thread/ecc0b2e4-8661-420a-bdf5-d7af13567be2. If you are wanting to do this for multiple webs that have the same file name in their pages libraries, I'm sure you could modify this script to enumerate through those sites and perform the same action.


I would recommend using RootFolder.WelcomePage. However, there seems to be a strange issue where you have to actually get the Rootfolder object to do stuff, unless it won't be updated.

Alas, this doesn't work:

web.RootFolder.WelcomePage = "myHomepage.aspx";

But this will:

var folder = web.RootFolder;
folder.WelcomePage = "myHomepage.aspx";
  • 1
    This behavior is due to the fact the SPWeb.RootFolder internally calls new SPFolder(currentWeb,"") and returns that. Thus in the first block you get a new SPfolder twice, and call update on a non-changed version.
    – Dribbel
    Commented Sep 20, 2011 at 13:21

Assuming "web" is an SPWeb for the site you're trying to change:

web.RootFolder.WelcomePage = "URL to desired page";

See http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfolder.welcomepage.aspx

  • I did both web.RootFolder.WelcomePage = "Pages/MyCustom.aspx"; and PublishingWeb.DefaultPage in my code but after provisioning a spweb following comes up. web_A/Pages/default.aspx Status: Checked in and viewable by authorized users.
    – Roxanne
    Commented May 13, 2011 at 11:58
  • I deleted both oot default pages. SPFile file = web.GetFile("./pages/default.aspx"); file.Delete(); it is still showing up as default page. However, if i refresh and it's gone. buggie??
    – Roxanne
    Commented May 13, 2011 at 12:15
  • Probably. Do you mean in SharePoint Designer, the browser, or the SPWeb object? In all of those there may be issues with the cache.
    – Andy Burns
    Commented May 13, 2011 at 13:04
  • spweb object. hmm. so whats the fix Andy?
    – Roxanne
    Commented May 13, 2011 at 14:12
  • I'd suggest closing the SPWeb object and loading a new one. It does seem like a bug.
    – Andy Burns
    Commented May 17, 2011 at 12:56

For powershell, something like this should be a good start (of course dispose of resources) $web is an SPWeb object

$web2 = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web);

$web2.DefaultPage = $web2.Web.RootFolder.Files["Default.aspx"]


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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