0

I tried to add a wikipage in the wikipage library using the code provided by Vijai Anand Ramalingam on c-sharpcorner.com.

I'm copy-pasting the script here to avoid dead link issues preventing future readers from accessing it. I obviously replaced all the variables to allow the script to suits my local environnement.

$listName="A"
$siteURL="http://serverName:1111"
$site=Get-SPSite $siteURL
$web=$site.RootWeb
$list=$web.Lists[$listName]               
$rootFolder = $list.RootFolder
$wikiPage = $rootFolder.Files.Add("/"+$rootFolder+"/Home.aspx", [Microsoft.SharePoint.SPTemplateFileType]::WikiPage)
$wikiItem = $wikiPage.Item
$wikiItem[[Microsoft.SharePoint.SPBuiltInFieldId]::WikiField] = "Template Preview" 
$wikiItem.UpdateOverwriteVersion()

This code is not working because it throws the following error:

You cannot call a method on a null-valued expression

$wikiPage = $rootFolder.Files.Add("/"+$rootFolder+"/Home7.aspx", [Microsoft.Sh ...

1

Replace

$wikiPage = $rootFolder.Files.Add("/"+$rootFolder+"/Home.aspx", [Microsoft.SharePoint.SPTemplateFileType]::WikiPage)

by

$wikiPage = $rootFolder.Files.Add($rootFoler.ServerRelativeUrl + "/Home.aspx", [Microsoft.SharePoint.SPTemplateFileType]::WikiPage)

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.