Skip to main content
StorageFolder.GetItemsAsync(UInt32, UInt32) | getItemsAsync(UInt32, UInt32) method

Gets an index-based range of files and folders from the list of all files and subfolders in the current folder.

Syntax


storageFolder.getItemsAsync(startIndex, maxItemsToRetrieve).done( /* Your success and error handlers */ );

public IAsyncOperation<IReadOnlyList> GetItemsAsync(
  uint startIndex, 
  uint maxItemsToRetrieve
)

Public Function GetItemsAsync(
  startIndex As UInteger,  
  maxItemsToRetrieve As UInteger 
) As IAsyncOperation(Of IReadOnlyList)

public:
IAsyncOperation<IVectorView>^ GetItemsAsync(
  unsigned int startIndex, 
  unsigned int maxItemsToRetrieve
)

Parameters

startIndex

Type: Number [JavaScript] | System.UInt32 [.NET] | uint32 [C++]

The zero-based index of the first item in the range to get.

maxItemsToRetrieve

Type: Number [JavaScript] | System.UInt32 [.NET] | uint32 [C++]

The maximum number of items to get.

Return value

Type: IAsyncOperation<IVectorView>

When this method completes successfully, it returns a list of the files and subfolders in the current folder. The list is of type IReadOnlyList< IStorageItem>. Each item in the list is represented by an IStorageItem object.

To work with the returned items, call the IsOfType method of the IStorageItem interface to determine whether each item is a file or a folder. Then cast the item to a StorageFolder or StorageFile.

Exceptions

ExceptionCondition
System.UnauthorizedAccessException

You don't have permission to access the contents of the current folder.

Remarks

Call the IsOfType method of the IStorageItem interface to determine whether an item is a file or a folder.

This query is a shallow query that returns only items in the current folder. For a list of methods that identifies shallow queries and deep queries, see the Remarks in the topic GetItemsAsync.

To specify additional query options, call the CreateItemQueryWithOptions method.

To get only files, call the GetFilesAsync method. To get only folders, call the GetFoldersAsync method.

Examples

The following example shows how to get the first 10 files and subfolders in the current folder by calling the GetItemsAsync method.


using Windows.Storage;
using System.Threading.Tasks;
using System.Diagnostics; // For writing results to Output window.
...
            // Get the app's installation folder.
            StorageFolder appFolder =
                Windows.ApplicationModel.Package.Current.InstalledLocation;

            // Get the first 10 files and subfolders in the current folder.
            IReadOnlyList<IStorageItem> itemsInFolder =
                     await appFolder.GetItemsAsync(0, 10);

            // Iterate over the results and print the list of items
            // to the Visual Studio Output window.
            foreach (IStorageItem item in itemsInFolder)
            {
                if(item.IsOfType(StorageItemTypes.Folder))
                    Debug.WriteLine("Folder: " + item.Name);
                else
                    Debug.WriteLine("File: " + item.Name + ", " + item.DateCreated);
            }

// Get the app's installation folder.
var appFolder = Windows.ApplicationModel.Package.current.installedLocation;

// Get the first 10 files and subfolders in the current folder.
var itemsInFolderPromise = appFolder.getItemsAsync(0, 10);

// Iterate over the results and print the list of items
// to the Visual Studio Output window.
itemsInFolderPromise.done(function getItemsSuccess(itemsInFolder) {
    itemsInFolder.forEach(function forEachItem(item) {
        var StorageItemTypes = Windows.Storage.StorageItemTypes;
        if (item.isOfType(StorageItemTypes.folder)) {
            console.log("Folder:", item.name);
        } else {
            console.log("File:", item.name, item.dateCreated);
        }
    });
});

C++
 // Get the apps installation folder
 StorageFolder^ appFolder = Windows::ApplicationModel::Package::Current->InstalledLocation;

 // Get the first 10 items in the current folder; 
 create_task(appFolder->GetItemsAsync(0,10)).then([=](IVectorView<IStorageItem^>^ itemsInFolder) {

  //Iterate over the results and print the list of items
  // to the visual studio output window
  for (auto it = itemsInFolder->First(); it->HasCurrent; it->MoveNext())
  {
   IStorageItem^ item = it->Current;
   if (item->IsOfType(StorageItemTypes::File))
   {
    String^ output = "File: " + item->Name + "\n";
    OutputDebugString(output->Begin());
   }
   else
   {
    String^ output = "Folder: " + item->Name + "\n";
    OutputDebugString(output->Begin());
   }
  }
 });

Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

Windows.Storage
Windows::Storage [C++]

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8

Namespace

Windows.Storage
Windows::Storage [C++]

Metadata

Windows.winmd

See also

StorageFolder
GetItemsAsync
GetFilesAsync
GetFoldersAsync