StorageItemContentProperties StorageItemContentProperties StorageItemContentProperties StorageItemContentProperties Class

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

Syntax

Declaration

public sealed class StorageItemContentPropertiespublic sealed class StorageItemContentPropertiesPublic NotInheritable Class StorageItemContentPropertiespublic sealed class StorageItemContentProperties

Remarks

You can get a StorageItemContentProperties object using the Properties property that is available on the following objects:

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 retrieve content properties or specified properties from a file using Properties.

try
{
    StorageFile file = rootPage.sampleFile;
    if (file != null)
    {
        StringBuilder outputText = new StringBuilder();

        // Get image properties
        ImageProperties imageProperties = await file.Properties.GetImagePropertiesAsync();
        outputText.AppendLine("Date taken: " + imageProperties.DateTaken);
        outputText.AppendLine("Rating: " + imageProperties.Rating);

        // Specify more properties to retrieve
        readonly string dateAccessedProperty = "System.DateAccessed";
        readonly string fileOwnerProperty = "System.FileOwner";
        List<string> propertiesName = new List<string>();
        propertiesName.Add(dateAccessedProperty);
        propertiesName.Add(fileOwnerProperty);

        // Get the specified properties through StorageFile.Properties
        IDictionary<string, object> extraProperties = await file.Properties.RetrievePropertiesAsync(propertiesName);
        var propValue = extraProperties[dateAccessedProperty];
        if (propValue != null)
        {
            outputText.AppendLine("Date accessed: " + propValue);
        }
        propValue = extraProperties[fileOwnerProperty];
        if (propValue != null)
        {
            outputText.AppendLine("File owner: " + propValue);
        }
    }
}
// Handle errors with catch blocks
catch (FileNotFoundException)
{
 // For example, handle a file not found error
}

var file = SdkSample.sampleFile;
if (file !== null) {
    var outputDiv = document.getElementById("output");

    // Get image properties
    file.properties.getImagePropertiesAsync().then(function (imageProperties) {
        outputDiv.innerHTML += "Date taken: " + imageProperties.dateTaken + "<br/>";
        outputDiv.innerHTML += "Rating: " + imageProperties.rating + "<br/>";

        // Specify more properties to retrieve
        var dateAccessedProperty = "System.DateAccessed";
        var fileOwnerProperty    = "System.FileOwner";

        // Get the specified properties through storageFile.properties
        return file.properties.retrievePropertiesAsync([fileOwnerProperty, dateAccessedProperty]);
    }).done(function (extraProperties) {
        var propValue = extraProperties[dateAccessedProperty];
        if (propValue !== null) {
            outputDiv.innerHTML += "Date accessed: " + propValue + "<br/>";
        }
        propValue = extraProperties[fileOwnerProperty];
        if (propValue !== null) {
            outputDiv.innerHTML += "File owner: " + propValue;
        }
    },
    // Handle errors with an error function
    function (error) {
        // Handle errors encountered while retrieving properties
    });
}

After GetImagePropertiesAsync() completes, imageProperties gets a ImageProperties object. Additionally, after RetrievePropertiesAsync(IIterable<String>) completes, extraProperties gets an object that contains the specified properties.

In the example, file contains a StorageFile that represents the file to retrieve properties for.

Methods summary

Retrieves the document properties of the item (like a file of folder).

Retrieves the image properties of the item (like a file of folder).

Retrieves the music properties of the item (like a file of folder).

Retrieves the video properties of the item (like a file of folder).

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.

Methods

  • GetDocumentPropertiesAsync()
    GetDocumentPropertiesAsync()
    GetDocumentPropertiesAsync()
    GetDocumentPropertiesAsync()

    Retrieves the document properties of the item (like a file of folder).

    public IAsyncOperation<DocumentProperties> GetDocumentPropertiesAsync()public IAsyncOperation<DocumentProperties> GetDocumentPropertiesAsync()Public Function GetDocumentPropertiesAsync() As IAsyncOperation( Of DocumentProperties )public IAsyncOperation<DocumentProperties> GetDocumentPropertiesAsync()

    Returns

    Remarks

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

  • GetImagePropertiesAsync()
    GetImagePropertiesAsync()
    GetImagePropertiesAsync()
    GetImagePropertiesAsync()

    Retrieves the image properties of the item (like a file of folder).

    public IAsyncOperation<ImageProperties> GetImagePropertiesAsync()public IAsyncOperation<ImageProperties> GetImagePropertiesAsync()Public Function GetImagePropertiesAsync() As IAsyncOperation( Of ImageProperties )public IAsyncOperation<ImageProperties> GetImagePropertiesAsync()

    Returns

    • When this method completes successfully, it returns an ImageProperties object.

  • GetMusicPropertiesAsync()
    GetMusicPropertiesAsync()
    GetMusicPropertiesAsync()
    GetMusicPropertiesAsync()

    Retrieves the music properties of the item (like a file of folder).

    public IAsyncOperation<MusicProperties> GetMusicPropertiesAsync()public IAsyncOperation<MusicProperties> GetMusicPropertiesAsync()Public Function GetMusicPropertiesAsync() As IAsyncOperation( Of MusicProperties )public IAsyncOperation<MusicProperties> GetMusicPropertiesAsync()

    Returns

    • When this method completes successfully, it returns a MusicProperties object.

  • GetVideoPropertiesAsync()
    GetVideoPropertiesAsync()
    GetVideoPropertiesAsync()
    GetVideoPropertiesAsync()

    Retrieves the video properties of the item (like a file of folder).

    public IAsyncOperation<VideoProperties> GetVideoPropertiesAsync()public IAsyncOperation<VideoProperties> GetVideoPropertiesAsync()Public Function GetVideoPropertiesAsync() As IAsyncOperation( Of VideoProperties )public IAsyncOperation<VideoProperties> GetVideoPropertiesAsync()

    Returns

    • When this method completes successfully, it returns a VideoProperties object.

  • 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. The list of supported properties can be found on the System properties page.

    Returns

    • When this method completes successfully, it returns a collection (type IMap<K, V> ) that contains the specified properties and values as key-value pairs. The return value of properties can be null.

    Remarks

    Expando properties can be retrieved by RetrievePropertiesAsync(IIterable<String>). See the remarks under SavePropertiesAsync(IIterable<IKeyValuePair<String, Object>>).

  • 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

    Remarks

    System.ExpandoProperties

    Expando properties are a set of named values associated with a storage file instance in memory. They are not saved persistently in the file system but are retained when a file is saved in the access cache.

    They can be written and read by any app, and therefore provide a way to associate information with a storage file. This is useful in scenarios where a storage file is passed from one app to another to communicate extra information about that file.

    Expando properties are accessed using the Windows Runtime storage API. They are retrieved as a value using RetrievePropertiesAsync(IIterable<String>) with the "System.ExpandoProperties" property name. The expando properties are written using SavePropertiesAsync(IIterable<IKeyValuePair<String, Object>>). That value is a property set itself so the values within it are accessed using the PropertySet programming model.

    The names used to identify values in the System.ExpandoProperties set do not need to conform to the system's property naming scheme (which prefixes property names with "System"). They can be any string value.

    The system defines some of the names that should be used. For example, "OriginURL" is used to communicate where a locally-stored file came from if it was downloaded from a remote source. (See Customizing the download experience.)

    Apps may define and document the properties that they use so other applications can interoperate with them. For example, System.ExpandoProperties can be used to allow a provider app to pass license information to a Universal Office app, to indicate whether a file can be personal or for business.

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