문제

Is there a way to get a count of the files under a folder in a SharePoint 2010 (enterprise) document library?

도움이 되었습니까?

해결책

This may help - Gathering item count for all document libraries in a Site Collection (PowerShell script with some tweaking needed).

다른 팁

This works perfect for me $list.Items.Count in the following script:

$SPWebApp = Get-SPWebApplication "http://dev.company.com/"

foreach ($SPSite in $SPWebApp.Sites)
{
    if ($SPSite -ne $null)
    {
        foreach ($SPWeb in $SPSite.AllWebs)
        {
            foreach ($list in $SPWeb.Lists)
            {
                if($list.BaseType -eq "DocumentLibrary")
                {
                    $ListURL = $SPWeb.url + "/" + $list.RootFolder.Url
                    Write-Host $ListURL
                    Write-Host "  No of item: " $list.Items.Count

                    if ($SPWeb -ne $null)
                    {
                        $SPWeb.Dispose()
                    }
                }
            }
        }
    }

    if ($SPSite -ne $null)
    {
        $SPSite.Dispose()
    }
}

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfilecollection.count.aspx

SPFolder.Files.Count

is what you are looking for I believe.

SPFolder.ItemCount will give you the number of items in the folder, but this is both files and subfolder and only direct children

If you only need the file count then the SPFolder.ItemCount - SPFolder.SubFolders.Count may be faster than SPFolder.Files.Count if there are a lot more files than folders and you're not going to use the SPFile objects for anything.

To get all files regardless of level you may loop through subfolders recursively.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top