-api-id | -api-type |
---|---|
T:Windows.Storage.FileProperties.DocumentProperties |
winrt class |
Provides access to the document-related properties of an item (like a file or folder).
You can access a DocumentProperties object asynchronously using the GetDocumentPropertiesAsync method from the Properties property of an item (like a file of folder), or synchronously using the DocumentProperties property if it is available. You can get a DocumentProperties object using any of the following methods and properties:
- FileInformation.documentProperties property
- FolderInformation.documentProperties property
- StorageItemContentProperties.getDocumentPropertiesAsync method, which can be accessed using the Properties property, if it is available.
Note
Properties that are get or set using a property handler that is defined by another app (like Microsoft Word) may not be accessible. Instead, you can try to get these properties using a file query that is backed by the system index. For more information, see QueryOptions.
For more code samples about accessing properties, see the File access sample.
This example demonstrates how to use a file query that is backed by the system index to retrieve document properties like Title.
try
{
// Create index backed file query and get results
List<string> fileTypeFilter = new List<string>();
fileTypeFilter.Add(".docx");
QueryOptions queryOptions = new QueryOptions(Windows.Storage.Search.CommonFileQuery.OrderByName, fileTypeFilter);
queryOptions.IndexerOption = IndexerOption.OnlyUseIndexer;
StorageFileQueryResult queryResult = Windows.Storage.KnownFolders.DocumentsLibrary.CreateFileQueryWithOptions(queryOptions);
var files = await queryResult.GetFilesAsync();
// Process resulting files
if (files.Count == 0)
{
// Perform tasks to handle no files found
}
else
{
// Access properties for each file
foreach (StorageFile file in files)
{
var documentProperties = await file.Properties.GetDocumentPropertiesAsync();
// Perform tasks with document properties
String title = documentProperties.Title;
}
}
}
// Handle errors with catch blocks
catch (FileNotFoundException)
{
// For example, handle a file not found error
}
While the example uses the DocumentsLibrary to create the query, you can create a query like this for any folder you have access to that you can get as a StorageFolder.
In the example, file
contains a StorageFile that represents the file to retrieve properties for.
StorageItemContentProperties.getDocumentPropertiesAsync method, Windows.Storage.BulkAccess.FileInformation.documentProperties property, Windows.Storage.BulkAccess.FolderInformation.documentProperties property, Windows.Storage.BulkAccess.IStorageItemInformation.DocumentProperties property