2015-11-04 56 views
1

嗨我正尝试使用SQL表中的数据在线连接并发布日历,并收到以下异常,请指教。同样的代码可以正常工作,只需稍微修改一下就可以使用Sharepoint服务器我已经添加了sharepointonline进行身份验证,但是由于错误而失败。使用Powershell连接到sharepoint oniline:无法找到类型为Microsoft.SharePoint.Client.ClientContext的适当构造函数

[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() 
} 

异常

新对象:一个构造函数没有被发现。找不到适用于Microsoft.SharePoint.Client.ClientContext类型的适当的 构造函数。在 C:\ MOSSLibrary \ testingpublish.ps1:15 char:12 + $ Context = New-Object Microsoft.SharePoint.Client.ClientContext($ site ... +
~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :ObjectNotFound:(:) [New-Object],PSArgumentException + FullyQualifiedErrorId:CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand 无法在此对象上找到属性'Credentials'。验证 该属性是否存在并可以进行设置。在 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

似乎组件无法正常加载。

[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 
相关问题