4

I have a Sharepoint 2013 instance running on a server. I want to create a script that writes wiki pages from files. So while searching the internet, I found some code for C#, VB, and some PS Code that was not exactly doing what I wanted.

What I have so far:

$pageLayout = '<div class="ExternalClassCFBA8CDC81B34264A81647E2260499B4"><table id="layoutsTable" style="width:100%"><tbody><tr style="vertical-align:top"><td colspan="2"><div class="ms-rte-layoutszone-outer" style="width:100%"><div class="ms-rte-layoutszone-inner"><div class="ExternalClass84D2F659CA274C02B313B2039A7DCEF6">Template Preview</div></div></div></td></tr><tr style="vertical-align:top"><td style="width:49.95%"><div class="ms-rte-layoutszone-outer" style="width:100%"><div class="ms-rte-layoutszone-inner"><div class="ExternalClass84D2F659CA274C02B313B2039A7DCEF6"> </div></div> </div></td><td style="width:49.95%"><div class="ms-rte-layoutszone-outer" style="width:100%"><div class="ms-rte-layoutszone-inner"></div> </div></td></tr></tbody></table><span id="layoutsData" style="display:none">true,false,2</span></div>';
$SPSite = New-Object Microsoft.SharePoint.SPSite("http://sharepoint");
$OpenWeb = $SpSite.OpenWeb();
$rootFolder = $OpenWeb.Lists['MyWiki'].RootFolder;
$files = $rootFolder.Files;
$newPage = $files.Add($rootFolder.ServerRelativeUrl + "/Testpage", [Microsoft.SharePoint.SPTemplateFileType]::WikiPage);
# Dispose stuff...

I already get an exception here:

Exception calling "Add" with "2" argument(s): ""
At C:\createWiki.ps1:31 char:5
+     $newPage = $files.Add($rootFolder.ServerRelativeUrl + "/Testpage", [Micr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SPException

But the parameters seem to be correct. What am I doing wrong?

  • try this one on $file.add($rootFolder.ServerRelativeUrl + "/Testpage.aspx", [Microsoft.SharePoint.SPTemplateFileType]::WikiPage) – Waqas Sarwar MVP Jul 3 '14 at 7:25
1

Thanks for your question. You first part helped me a lot. I implemented your script with .aspx after the page title. That works fine.

Your example works like this:

$pageLayout = '<div class="ExternalClassCFBA8CDC81B34264A81647E2260499B4"><table id="layoutsTable" style="width:100%"><tbody><tr style="vertical-align:top"><td colspan="2"><div class="ms-rte-layoutszone-outer" style="width:100%"><div class="ms-rte-layoutszone-inner"><div class="ExternalClass84D2F659CA274C02B313B2039A7DCEF6">Template Preview</div></div></div></td></tr><tr style="vertical-align:top"><td style="width:49.95%"><div class="ms-rte-layoutszone-outer" style="width:100%"><div class="ms-rte-layoutszone-inner"><div class="ExternalClass84D2F659CA274C02B313B2039A7DCEF6"> </div></div> </div></td><td style="width:49.95%"><div class="ms-rte-layoutszone-outer" style="width:100%"><div class="ms-rte-layoutszone-inner"></div> </div></td></tr></tbody></table><span id="layoutsData" style="display:none">true,false,2</span></div>';
$SPSite = New-Object Microsoft.SharePoint.SPSite("http://sharepoint");
$OpenWeb = $SpSite.OpenWeb();
$rootFolder = $OpenWeb.Lists['MyWiki'].RootFolder;
$files = $rootFolder.Files;
$newPage = $files.Add($rootFolder.ServerRelativeUrl + "/Testpage.aspx", [Microsoft.SharePoint.SPTemplateFileType]::WikiPage);
# Dispose stuff...

By the way; You're not using your page layout in this example.

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.