【发布时间】:2014-05-12 21:07:45
【问题描述】:
几天以来,我一直在努力使用 powershell 将文件上传到 Sharepoint 2010。 我在一台装有 powershell v2 的 win7 机器上尝试上传到 SP 2010 站点。
我有两个主要问题
- $Context.web 值始终为空,即使在 Executequery() 之后也没有 显示错误。我的 $Context 变量获取服务器版本 (14.x.x.x.x),仅此而已
- $Context.Load($variable) 总是返回错误找不到“Load”的重载和参数计数:“1”。
我将 Sharepoint DLL 复制到我的 Win7 机器上,并将引用导入到我的脚本中。 下面的脚本是我从网上获取的许多部分的混合。
我已经尝试在定义 Load 方法的客户端上下文上添加重载但没有成功 http://soerennielsen.wordpress.com/2013/08/25/use-csom-from-powershell/
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
$site = "https://Root-of-my-site"
$listname = "My-folder"
$context = New-Object Microsoft.SharePoint.Client.ClientContext($site)
[Microsoft.SharePoint.Client.Web]$web = $context.Web
[Microsoft.SharePoint.Client.List]$list = $web.Lists.GetByTitle($listName)
$Folder = "C:\temp\Certificates"
$List = $Context.Web.Lists.GetByTitle($listname)
Foreach ($File in (dir $Folder))
{
$FileCreationInfo = New-Object Microsoft.SharePoint.Client.FileCreationInformation
$FileCreationInfo.Overwrite = $true
$FileCreationInfo.Content = get-content -encoding byte -path $File.Fullname
$FileCreationInfo.URL = $File
$Upload = $List.RootFolder.Files.Add($FileCreationInfo)
$Context.Load($Upload)
$Context.ExecuteQuery()
}
错误是
找不到“Load”的重载和参数计数:“1”。 在 C:\temp\uploadCertToSharepoint.ps1:48 char:14 + $Context.Load
有人可以帮我解决这个问题吗? 我需要在几周内将大约 400 个带有临时字段的文件上传到共享点站点,而此刻我完全陷入困境。不幸的是,无法运行脚本服务器端。
谢谢, 马可
【问题讨论】:
-
我在使用您的脚本时没有收到指定的错误。我在其中更改了 1 行,它按预期工作。也许您遇到了其他错误?
-
糟糕,抱歉,已在 SharePoint 2013 和 Powershell 3 上进行了测试。:)
标签: sharepoint-2010 powershell-2.0 sharepoint-clientobject