首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SharePoint在线迭代文档库

SharePoint在线迭代文档库
EN

Stack Overflow用户
提问于 2015-01-29 23:18:53
回答 1查看 2.1K关注 0票数 1

我正在尝试迭代文档库,并将每个文档/项目设置为继承权限(目前每个文档/项目都使用唯一的权限)。

我能够获得特定的文档库,但是我不能遍历其中的每个项目/文档。这就是我到目前为止所知道的:

代码语言:javascript
复制
Add-Type -Path "Libraries\Microsoft.SharePoint.Client.dll" 
Add-Type -Path "Libraries\Microsoft.SharePoint.Client.Runtime.dll" 
Add-Type -Path "Libraries\Microsoft.SharePoint.Linq.dll"
Add-Type -Path "Libraries\Microsoft.SharePoint.dll"

$webUrl = "https://test.sharepoint.com/sites/testsite" 
$username = "####"
$password = "####"
$securePass = ConvertTo-SecureString $password -AsPlainText -Force
$listname = "TestDoc";

$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($webUrl)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePass)

#variables
$web = $ctx.Web
$lists = $web.Lists
$ctx.Load($lists)
$ctx.Load($web)
$ctx.ExecuteQuery()

#print web URL
write-host `n "Web Url:" `n $web.Url

foreach ($list in $lists)
{

    if ($list.Title -eq "TestDoc")
    {
        #print list name if found
        write-host `n "Found the list:" `n $list.Title `n


            #attempting to iterate through items in the document library 
            foreach ($item2 in $list.Items)
            {
                #list the items/documents  in the document library
                write-host $item2.Title 
            }


    }
}

这是foreach循环,我现在遇到了麻烦,因为我不确定如何遍历文档库中的每个项目/文档。

任何关于我应该采取的方法的建议都将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2015-02-02 22:10:10

我得到的错误是:

找不到"Load“和参数count:"1”的重载。At C:\Users\setup\Desktop\Test-BreakInheritence-Script-SPOnline\Permissions-Inh eritence.ps1:38 char:3 + $ctx.Load($items) +~+ CategoryInfo : NotSpecified:(:) [],MethodException + FullyQualifiedErrorId:

与Load()方法有关,该方法需要传入附加参数。我认为只有在处理list/listItems时才需要这样做。我没有花太多时间调查确切的根本原因,但我已经修改了我的解决方案,并使其变得更简单:

代码语言:javascript
复制
Add-Type -Path "Libraries\Microsoft.SharePoint.Client.dll" 
Add-Type -Path "Libraries\Microsoft.SharePoint.Client.Runtime.dll" 
Add-Type -Path "Libraries\Microsoft.SharePoint.Linq.dll"
Add-Type -Path "Libraries\Microsoft.SharePoint.dll"

    $webUrl = "https://test.sharepoint.com/sites/testsite" 
    $username = "####"
    $password = "####"
    $securePass = ConvertTo-SecureString $password -AsPlainText -Force
    $listname = "TestDoc"

    $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($webUrl)
    $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePass)


    #get the List/DocLib and load it for use
    $listUpdate = $ctx.Web.Lists.GetByTitle($listname)
    $ctx.Load($listUpdate)
    $ctx.ExecuteQuery()

    #CAML Query to get all items inclusing sub-folders
    $spQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
    $spQuery.ViewXml = "<View Scope='RecursiveAll' />";
    $itemki = $listUpdate.GetItems($spQuery)
    $ctx.Load($itemki)
    $ctx.ExecuteQuery()

    #iterating through the items and reseting permission inheritence
    for($j=0; $j -lt $itemki.Count; $j++)
    {
        $itemki[$j].ResetRoleInheritance()
        $ctx.ExecuteQuery()
    }

现在,这就像一种护身符。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28218152

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档