您好我正在尝试连接到sharepoint在线并使用SQL表中的数据发布日历,我收到以下异常,请指教。相同的代码工作正常,稍微修改我已经添加的一个前端sharepoint服务器用于身份验证的sharepointonline但是它失败并出现错误。
[System.Reflection.Assembly]::LoadFile ("C:\MOSSLibrary\Microsoft.SharePoint.Client.dll") | Out-Null
[System.Reflection.Assembly]::LoadFile("C:\MOSSLibrary\Microsoft.SharePoint.Client.Runtime.dll") | Out-Null
$username = "XXXXXX"
$url = "XXXXXX"
$pass= cat C:\text.txt | ConvertTo-SecureString
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username,$Pass)
$Context.Credentials = $Creds
$web = $Context.Web
$Context.Load($web)
$Context.Load($splist)
$splist = $Context.web.Lists.GetByTitle("XXXX")
$ItemCreateInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
####Some Data coming from SQL Server DB into $table########
$table = $result.Tables[0];
foreach ($row in $table)
{
Write-Host $row.Item("changetitle") $row.Item("status");
$Item1 = $splist.AddItem($ItemCreateInfo)
$Item1["Title"] = "test"
Write-host $date
$Item1.Update()
$Context.ExecuteQuery()
}
例外
New-Object:找不到构造函数。找不到合适的 Microsoft.SharePoint.Client.ClientContext类型的构造函数。在 C:\ MOSSLibrary \ testingpublish.ps1:15 char:12 + $ Context = New-Object Microsoft.SharePoint.Client.ClientContext($ site ... +
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~ + CategoryInfo:ObjectNotFound:(:) [New-Object],PSArgumentException + FullyQualifiedErrorId:CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand 无法在此对象上找到属性“凭据”。校验 该属性存在且可以设置。在 C:\ MOSSLibrary \ testingpublish.ps1:17 char:1 + $ Context.Credentials = $ Creds + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:InvalidOperation:(:) [],RuntimeException + FullyQualifiedErrorId:PropertyNotFound您无法在空值表达式上调用方法。在 C:\ MOSSLibrary \ testingpublish.ps1:20 char:1 + $ Context.Load($ web)+ ~~~~~~~~~~~~~~~~~~~ + CategoryInfo:InvalidOperation:(:) [],RuntimeException + FullyQualifiedErrorId:InvokeMethodOnNull您无法在空值表达式上调用方法。在 C:\ MOSSLibrary \ testingpublish.ps1:21 char:1 + $ Context.Load($ splist) + ~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:InvalidOperation:(:) [],RuntimeException + FullyQualifiedErrorId:InvokeMethodOnNull您无法在空值表达式上调用方法。在 C:\ MOSSLibrary \ testingpublish.ps1:22 char:1 + $ splist = $ Context.web.Lists.GetByTitle(“XXXXXXX”)+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~ + CategoryInfo:InvalidOperation:(:) [],RuntimeException + FullyQualifiedErrorId:InvokeMethodOnNull
答案 0 :(得分:1)
似乎装配体未正确加载。
[System.Reflection.Assembly]::LoadFile ("C:\MOSSLibrary\Microsoft.SharePoint.Client.dll") | Out-Null
[System.Reflection.Assembly]::LoadFile("C:\MOSSLibrary\Microsoft.SharePoint.Client.Runtime.dll") | Out-Null
而不是上述内容,请尝试按照
Add-Type -Path "C:\MOSSLibrary\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\MOSSLibrary\Microsoft.SharePoint.Client.Runtime.dll"
PS:确保C:\MOSSLibrary\
包含以下两个.dll
Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.Client.Runtime.dll