3

I need to change my default page of my site :

$assignment = Start-SPAssignment

    $web.RootFolder.WelcomePage ="Pages/"+ $page
    $web.RootFolder.Update()
    Stop-SPAssignment $assignment

But the welcome page still the same. My site is publish site, is there another solution .

  • Try $web.RootFolder.WelcomePage = $page. Assuming $page is the url of the page (ie. default.aspx). Not sure if it will pick up pages from Pages library, but this definitely works for Site Pages. – Paul Strupeikis Oct 14 '16 at 14:15
  • Yes it works fine for Teamsite , but not on publish site . – Imen Turki Oct 14 '16 at 15:49
3

You said that you are working with a publishing enabled site. As far as I know, the code you are using can't work on Publishing sites, you should use the .DefaultPage property provided by the PublishingSite class instead.

Try something like this:

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

// note: pageFile is the acuall SPFile for the page, not just the url.
$publishingWeb.DefaultPage =$pageFile; 
$publishingWeb.Update();

Notice that you have to get a PublishingWeb first - think of it like a sort of wrapper that extends the normal SPWeb object and provides new functionalities specific for publishing enabled web sites.

0

The problem with this is that everytime you instantiate $web.RootFolder it grabs a new object form the DB so your call to .Update() is actually doing nothing.

Try the following code:

$folder = $web.RootFolder
$folder.WelcomePage = "Pages/" + $page
$folder.Update()

This should work.

  • Still the same ! – Imen Turki Oct 14 '16 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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