Windows Dev Center

Expand Minimize

StorageFolder.CreateItemQuery | createItemQuery method

Gets a query result object that contains the files and subfolders in the current folder.

Syntax


public:
StorageItemQueryResult^ CreateItemQuery()

Parameters

This method has no parameters.

Return value

Type: StorageItemQueryResult

A query result object. Call the GetItemsAsync method of the query result to get the files and subfolders in the current folder. This method returns a list of type IReadOnlyList<IStorageItem>. Each file or folder is represented by an item of type IStorageItem.

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

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.

You can also get a list of items in the current folder asynchronously by calling one of the GetItemsAsync methods.

To specify additional query options, call the CreateItemQueryWithOptions method.

To get only files, call the CreateFileQuery method. To get only folders, call the CreateFolderQuery method.

Examples

The following example shows how to get the files and subfolders in the current folder by calling the CreateItemQuery() method.


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

	StorageItemQueryResult^ results = appFolder->CreateItemQuery();

	// Get the items in the current folder; 
	create_task(results->GetItemsAsync()).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

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

None supported

Namespace

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

Metadata

Windows.winmd

See also

StorageFolder

 

 

Show:
© 2015 Microsoft