Share via


StorageFileQueryResult 類別

定義

提供 StorageFolder 物件所代表位置中檔案查詢結果的存取權。 您可以使用 StorageFileQueryResult 來列舉該 StorageFolder 位置中的檔案。

public ref class StorageFileQueryResult sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
class StorageFileQueryResult final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
public sealed class StorageFileQueryResult
Public NotInheritable Class StorageFileQueryResult
繼承
Object Platform::Object IInspectable StorageFileQueryResult
屬性
實作

Windows 需求

裝置系列
Windows 10 (已於 10.0.10240.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)

範例

此範例示範如何從 StorageFileQueryResult 物件取得檔案清單。

// Set query options with filter and sort order for results
List<string> fileTypeFilter = new List<string>();
fileTypeFilter.Add(".jpg");
fileTypeFilter.Add(".png");
fileTypeFilter.Add(".bmp");
fileTypeFilter.Add(".gif");
var queryOptions = new QueryOptions(CommonFileQuery.OrderByName, fileTypeFilter);

// Create query and retrieve files
var query = KnownFolders.PicturesLibrary.CreateFileQueryWithOptions(queryOptions);
IReadOnlyList<StorageFile> fileList = await query.GetFilesAsync();
// Process results
foreach (StorageFile file in fileList)
{
    // Process file
}

變數 query 會取得 StorageFileQueryResult,用來擷取符合查詢準則的檔案。

注意

您需要圖片庫功能,才能使用 KnownFolders.PicturesLibrary存取媒體櫃。 若要深入瞭解功能和檔案存取,請參閱 檔案存取權限

備註

注意

雖然它不是使用 marshalling_behavior(agile) 屬性,但這個類別可以視為敏捷式。

您可以從 StorageFolderFolderInformation 物件呼叫下列方法,以取得 StorageFileQueryResult 物件:

屬性

Folder

取得查詢以建立 StorageFileQueryResult 物件的資料夾。 此資料夾代表查詢的範圍。

方法

ApplyNewQueryOptions(QueryOptions)

根據新的 QueryOptions修改查詢結果。

FindStartIndexAsync(Object)

如果與 FileActivatedEventArgs.NeighboringFilesQuery) 搭配使用,則從最符合指定屬性值 (或檔案的查詢結果擷取檔案的索引。 相符的屬性是由QueryOptions.SortOrder清單的第一個SortEntry所決定。

GetCurrentQueryOptions()

擷取用來判斷查詢結果的查詢選項。

GetFilesAsync()

擷取查詢結果集中所有檔案的清單。

GetFilesAsync(UInt32, UInt32)

擷取指定範圍內的檔案清單。

GetItemCountAsync()

擷取查詢結果集中的檔案數目。

GetMatchingPropertiesWithRanges(StorageFile)

取得與對應文字範圍的相符檔案屬性。

事件

ContentsChanged

在查詢的資料夾中新增、刪除或修改檔案時引發。 只有在 呼叫 GetFilesAsync 至少一次之後,才會引發此事件。

OptionsChanged

查詢選項變更時引發。

適用於

另請參閱