将不同程序集中的加载问题发送到Powershell

时间:2014-07-23 09:11:30

标签: powershell powershell-v3.0 csom sharepoint-online

我一直在尝试将程序集加载到PowerShell for sharepoint,并且大多数工作正常,如下所示:

Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" 
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" 

但是当我尝试添加具有不同文件路径的那些时:

Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\ClientBin\Microsoft.SharePoint.Client.Silverlight.dll"

我收到以下错误:

  

“Add-Type:无法加载一个或多个请求的类型。检索LoaderExceptions属性以获取更多信息。”

任何人都可以帮忙吗?

- - - - - - - - UPDATE

    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
   #Bind to site collection
   $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
   $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)
   $Context.Credentials = $Creds

   #Retrieve list
   $List = $Context.Web.Lists.GetByTitle($DocLibName)
   $Context.Load($List)
   $Context.ExecuteQuery()

    $SPFolder = New-Object Microsoft.SharePoint.Client.Folder

1 个答案:

答案 0 :(得分:0)

Microsoft.SgarePoint.Client.Folder定义为in multiple assemblies,每个平台支持一个 public Folder( ClientRuntimeContext context, ObjectPath objectPath ) 。鉴于powershell在Desktop CLR上运行,您只需要加载程序集的桌面版本:

  

Microsoft.SharePoint.Client.Silverlight(在Microsoft.SharePoint.Client.Silverlight.dll中);

     

Microsoft.SharePoint.Client.Phone(在Microsoft.SharePoint.Client.Phone.dll中)

     

Microsoft.SharePoint.Client(在Microsoft.SharePoint.Client.dll中)

您需要传入正确的构造函数参数:

{{1}}

但我认为使用以下方法(GetFolderByServerRelativeUrl)更容易。