Change the home page of a wiki library
-
08-10-2020 - |
Question
I saved an old wiki library as a template w/ content and then created a wiki library from that template. The new wiki, however, shows all the wiki pages in a list of files because the new wiki home page URL is "/Forms/AllPages.aspx" instead of the normal default "home.aspx".
The "home.aspx" page is in the list of the wiki pages and I want to make it the default home page for my wiki like it would be if I made a wiki from scratch. Is this possible to change?
I've tried opening the site in SP Designer, selecting "home.aspx", and setting it as the home page. This set's my top-level site's homepage, though, which is not what I want.
Additional Details: Using SP Online for new location, the old library was on-premise SP2010.
Solution
You should be able to achieve this using CSOM. The sample code below works on a Wiki Page Library created in Office 365:
# Enter your credentials and the site URL here
$username = "user@mydomain.onmicrosoft.com"
$password = "Pass@word"
$url = "https://mydomain.sharepoint.com/sites/MyTeamSite"
$securePassword = ConvertTo-SecureString $Password -AsPlainText -Force
# The path here may need to change
# Copy the SP2013 DLLs into a suitable location such as c:\Lib
Add-Type -Path "C:\Lib\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Lib\Microsoft.SharePoint.Client.Runtime.dll"
# connect/authenticate to SharePoint Online and get ClientContext object...
$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
$clientContext.Credentials = $credentials
if (!$clientContext.ServerObjectIsNull.Value)
{
Write-Host "Connected to SharePoint Online site: $Url"
}
# Grab the root web context
$rootWeb = $clientContext.Web
$clientContext.Load($rootWeb)
$clientContext.ExecuteQuery()
# Grab the lists
$lists = $rootWeb.Lists
$clientContext.Load($lists)
$clientContext.ExecuteQuery()
# Find the correct list. Enter the title of your list.
$list = $clientContext.Web.Lists | where {$_.Title -eq "Wiki"}
$clientContext.Load($list)
$clientContext.ExecuteQuery()
# Set the root folder welcome page to the correct value and update
$list.RootFolder.WelcomePage="Home.aspx"
$list.RootFolder.Update()
$clientContext.ExecuteQuery()
I hope that helps!