Frage

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

War es hilfreich?

Lösung

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

Andere Tipps

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit sharepoint.stackexchange
scroll top