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".
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".
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";
web.RootFolder.Update();
But this will:
var folder = web.RootFolder;
folder.WelcomePage = "myHomepage.aspx";
folder.Update();
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
Sep 20 '11 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
web_A/Pages/default.aspx Status: Checked in and viewable by authorized users.
– Roxanne May 13 '11 at 11:58For 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"]
$web2.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 May 09 '11 at 19:48