![](/img/trans.png)
[英]Upload file to Sharepoint Online (Microsoft 365) using Powershell (Option 4 - Using Microsoft.SharePoint.Client.ClientContext)
[英]Casting [Microsoft.SharePoint.Client.ClientContext] to a Powershell Class Method results in an error
这是我的代码:
Class Tracker : WebObject {
$url
$username
$password
[Microsoft.SharePoint.Client.ClientContext] Context() {
$context = New-Object Microsoft.SharePoint.Client.ClientContext($this.url)
return $context
}
Tracker ([string]$url,[string]$username,[string]$password) {
$this.url = $url
$this.username = $username
$this.password = $password
}
我在脚本顶部添加了require dll:
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
但是,当我运行它时,出现以下错误:
Unable to find type [Microsoft.SharePoint.Client.ClientContext].
对出什么问题有任何想法吗?
我发现了这一点:您无法在使用类的脚本中导入dll。 解决方法是将二进制文件导入另一个脚本并通过点源包含类的脚本来加载类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.