DocumentProperties DocumentProperties DocumentProperties DocumentProperties Class

Provides access to the document-related properties of an item (like a file or folder).

Syntax

Declaration

public sealed class DocumentPropertiespublic sealed class DocumentPropertiesPublic NotInheritable Class DocumentPropertiespublic sealed class DocumentProperties

Remarks

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:

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.

Examples

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
}

// Create index backed file query and get results
var documentsLibrary = Windows.Storage.KnownFolders.documentsLibrary;
var fileTypeFilter = [".docx"];
var queryOptions = new Windows.Storage.Search.QueryOptions(Windows.Storage.Search.CommonFileQuery.orderByName, fileTypeFilter);
queryOptions.indexerOption = Windows.Storage.Search.IndexerOption.onlyUseIndexer;
var fileQuery = documentsLibrary.createFileQueryWithOptions(queryOptions);
fileQuery.getFilesAsync().then(function (files) {
    // Process resulting files
    if (files.size === 0) {
        // Perform tasks to handle no files found
    } else {
        // Access properties for each file
        files.forEach(function (file) {
            // Get document properties
            file.properties.getDocumentPropertiesAsync().done(function (documentProperties) {
                // Perform tasks with document properties
                var title = documentProperties.title;
            });
        });
    }
},
// Handle errors with an error function
function (error) {
    // Handle errors encountered while processing files
});

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.

Properties summary

Gets the collection of the document's authors.

Gets or sets the comments associated with the document.

Gets the collection of keywords associated with the document.

Gets or sets the title of the document.

Methods summary

Retrieves the specified properties associated with the item.

Saves all properties associated with the item.

Saves the specified properties and values associated with the item.

Properties

  • Author
    Author
    Author
    Author

    Gets the collection of the document's authors.

    public IVector<string> Author { get; }public IVector<string> Author { get; }Public ReadOnly Property Author As IVector<string>public IVector<string> Author { get; }

    Property Value

    • The name of the document author.

    Remarks

    This property is read-only. It returns a collection, and you can't delete or replace the collection itself. The contents of the collection, however, are not read-only. You can add items to the collection, remove items from the collection, and change existing items in the collection. Call the SavePropertiesAsync method of the parent class to save the updated contents of the collection.

  • Comment
    Comment
    Comment
    Comment

    Gets or sets the comments associated with the document.

    public string Comment { get; set; }public string Comment { get; set; }Public ReadWrite Property Comment As stringpublic string Comment { get; set; }

    Property Value

    • string
      string
      string
      string

      The comments.

  • Keywords
    Keywords
    Keywords
    Keywords

    Gets the collection of keywords associated with the document.

    public IVector<string> Keywords { get; }public IVector<string> Keywords { get; }Public ReadOnly Property Keywords As IVector<string>public IVector<string> Keywords { get; }

    Property Value

    • The collection of keywords.

    Remarks

    This property is read-only, similar to the Author property.

  • Title
    Title
    Title
    Title

    Gets or sets the title of the document.

    public string Title { get; set; }public string Title { get; set; }Public ReadWrite Property Title As stringpublic string Title { get; set; }

    Property Value

    • string
      string
      string
      string

      The document title.

Methods

  • RetrievePropertiesAsync(IIterable<String>)
    RetrievePropertiesAsync(IIterable<String>)
    RetrievePropertiesAsync(IIterable<String>)
    RetrievePropertiesAsync(IIterable<String>)

    Retrieves the specified properties associated with the item.

    public IAsyncOperation<IMap<string, object>> RetrievePropertiesAsync(IIterable<String> propertiesToRetrieve)public IAsyncOperation<IMap<string, object>> RetrievePropertiesAsync(IIterable<String> propertiesToRetrieve)Public Function RetrievePropertiesAsync(propertiesToRetrieve As IIterable<String>) As IAsyncOperation( Of IMapstring, object )public IAsyncOperation<IMap<string, object>> RetrievePropertiesAsync(IIterable<String> propertiesToRetrieve)

    Parameters

    • propertiesToRetrieve

      A collection that contains the names of the properties to retrieve.

    Returns

    • An object for managing the asynchronous property retrieval operation.

    Remarks

    In JavaScript, use then or done to specify handler functions that will capture and process the collection when it is returned.

  • SavePropertiesAsync()
    SavePropertiesAsync()
    SavePropertiesAsync()
    SavePropertiesAsync()

    Saves all properties associated with the item.

    public IAsyncAction SavePropertiesAsync()public IAsyncAction SavePropertiesAsync()Public Function SavePropertiesAsync() As IAsyncActionpublic IAsyncAction SavePropertiesAsync()

    Returns

    Remarks

    If any one of the property values is invalid, none of the values will be saved.

  • SavePropertiesAsync(IIterable<IKeyValuePair<String, Object>>)
    SavePropertiesAsync(IIterable<IKeyValuePair<String, Object>>)
    SavePropertiesAsync(IIterable<IKeyValuePair<String, Object>>)
    SavePropertiesAsync(IIterable<IKeyValuePair<String, Object>>)

    Saves the specified properties and values associated with the item.

    public IAsyncAction SavePropertiesAsync(IIterable<IKeyValuePair<String, Object>> propertiesToSave)public IAsyncAction SavePropertiesAsync(IIterable<IKeyValuePair<String, Object>> propertiesToSave)Public Function SavePropertiesAsync(propertiesToSave As IIterable<IKeyValuePair<String, Object>>) As IAsyncActionpublic IAsyncAction SavePropertiesAsync(IIterable<IKeyValuePair<String, Object>> propertiesToSave)

    Parameters

    • propertiesToSave

      A collection that contains the names and values of the properties to save as key-value pairs (type IKeyValuePair<K, V> ).

    Returns

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ContractVersionAttribute

Details

Assembly

Windows.Storage.FileProperties.dll