新网页的奇怪错误 - SP 2010 基金会



我在SP 2010基金会中使用NewWebPage xml命令时遇到了一个奇怪的问题。下面的代码不起作用

cls
Write-Host "Production Manager v8.0 Deployment Utility" -ForegroundColor red
Write-Host ""
#Starting the script. Lets see if we can find the configuration and map files first.
Write-Host -NoNewline "Checking for the Configuration.xml, PageMap.xml and  PageTemplate.xml files: " -ForegroundColor white
if((Test-Path "Configuration.xml") -and (Test-Path "PageMap.xml") -and (Test-Path "PageTemplate.xml"))
{
     Write-Host "FOUND" -ForegroundColor green
}
else
{
    Write-Host "NOT FOUND" -ForegroundColor red
    Write-Host "Check for the necessary files and try again."
    Write-Host ""
    Write-Host ""
    exit
}
Write-Host "Reading Configuration.xml"
[xml]$Configuration = Get-Content Configuration.xml
Write-Host "Reading PageMap.xml"
[xml]$PageMap = Get-Content PageMap.xml
Write-Host "Reading from Production Manager Site:    "$Configuration.Configuration.SiteConfiguration.SiteURL

#Some variables necessary for the loop
$pageCreationLoopIterations = 0
$pageLayout = ""
$pageTitle = ""
$createPageCommand = '<?xml version="1.0" encoding="UTF-8"?><Method ID="0,NewWebPage"><SetList Scope="Request">' + $productionManagerLibrary.ID + '</SetList><SetVar Name="Cmd">NewWebPage</SetVar><SetVar Name="ID">New</SetVar><SetVar Name="Type">WebPartPage</SetVar><SetVar Name="WebPartPageTemplate">' + $pageLayout + '</SetVar><SetVar Name="Overwrite">true</SetVar><SetVar Name="Title">MyPage</SetVar></Method>';
#Beginning the loop
Write-Host "Running through the PageMap file"
foreach($Page in $PageMap.Pages.Page)
{
     $web = Get-SPWeb $Configuration.Configuration.SiteConfiguration.SiteURL
     $productionManagerLibrary = $web.Lists | Where { $_.Title -eq "Production Manager" }
     $pageName = if($Page.SelectSingleNode("PageName")) { $Page.PageName } else {      $Configuration.Configuration.PageConfiguration.DefaultPageName }
     $pageLayout = if($Page.SelectSingleNode("PageLayout")) { $Page.PageLayout } else { $Configuration.Configuration.PageConfiguration.DefaultPageLayout }
     Write-Host 'Creating Page ' $pageName
     $web.ProcessBatchData($createPageCommand)

}

但是每次我运行它时,这个都可以正常工作:

$url = "http://mpm8/mpm";
$listname = "Production Manager"
$web = Get-SPWeb $url
$pagesLibrary = $web.Lists | Where { $_.Title -eq "Production Manager" }
$pageLayout = 8
$cmd = '<?xml version="1.0" encoding="UTF-8"?><Method ID="0,NewWebPage"><SetList Scope="Request">' + $pagesLibrary.ID + '</SetList><SetVar Name="Cmd">NewWebPage</SetVar><SetVar Name="ID">New</SetVar><SetVar Name="Type">WebPartPage</SetVar><SetVar Name="WebPartPageTemplate">' + $pageLayout + '</SetVar><SetVar Name="Overwrite">true</SetVar><SetVar Name="Title">MyPage</SetVar></Method>';
$web.ProcessBatchData($cmd)

我真的看不出这两个脚本之间有什么不同。我运行第一个时遇到的错误是:

<Result ID="0,NewWebPage" Code="-2130575350">
<ErrorText>Invalid URL Parameter.
The URL provided contains an invalid Command or Value. Please check the URL again.   </ErrorText></Result>

你能帮我这个吗?也许我不能把这个东西跑出一个 foreach 循环?:(

谢谢!

您首先设置了$createPageCommand(在循环之前),然后设置了第二个所需的变量(在循环中)。

如果在ISE中运行并逐步执行(即调试它),则可以看到变量及其值,否则只需在运行循环时发出要筛选的变量值,以确保正确设置它们。

因此,在您的示例中,将$createPageCommand放在循环中,并在设置$productionManagerLibrary之后。 然后,就在$web之前。ProcessBatchData($createPageCommand) 您应该发出 $createPageCommand 的值以确保它正常。

我只是在没有运行它的情况下盯着这个,但请我们知道这是否是原因!

相关内容

最新更新