1

I am trying to pick the list of documents from certain folder in a document library. The folder contains huge set of documents. To optimize performance we have been asked to use SPQuery command in script to retrieve the file list. When I used the below script I got all the files under the specified library. Can anyone help me to prepare the query to point to the folder and the items only from that folder. In this case it is 'Folderone'.

$spQuery = New-Object Microsoft.SharePoint.SPQuery
$spQuery.ViewAttributes = "Scope='Recursive'";
$spLibrary = $spListCollection.TryGetList($LibraryName)
$rfolder=$SPweb.Lists[$spLibrary].RootFolder.SubFolders["Folderone"]
$spQuery.Query ="<Where><BeginsWith><FieldRef Name='Folderone'/><Value Type='Folder'>Lib1/Folderone</Value></BeginsWith></Where>"
$spQuery.RowLimit = 200
do{
$folderItems = $splibrary.GetItems($spquery)
$spQuery.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
foreach($item in $folderItems)
    {
        Write-Host $item.Name
    }    
}while ($spQuery.ListItemCollectionPosition -ne $null)
2

You have to update the code and add the below line of code. The problem was you were getting the specific folder but was not assigning it to SPQuery.

$rfolder=$SPweb.Lists[$spLibrary].RootFolder.SubFolders["Folderone"]
//Add the below line of code
$spQuery.Folder = $rfolder;
  • Thanks. This code worked. But suddenly from morning I have started getting the error as.. "One or more field types are not installed properly. Go to the list settings page to delete these fields.". <br/> The code was working perfectly till night and the same code started throwing this error in the morning. – Vishal Aug 3 '17 at 5:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.