StorageItemContentProperties StorageItemContentProperties StorageItemContentProperties StorageItemContentProperties Class

Definition

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

public : sealed class StorageItemContentProperties : IStorageItemContentProperties, IStorageItemExtraProperties
public sealed class StorageItemContentProperties : IStorageItemContentProperties, IStorageItemExtraProperties
Public NotInheritable Class StorageItemContentProperties Implements IStorageItemContentProperties, IStorageItemExtraProperties
// This class does not provide a public constructor.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Examples

This example demonstrates how to retrieve content properties or specified properties from a file using StorageFile.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 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.

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.

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 )
Windows.Storage.FileProperties.StorageItemContentProperties.getDocumentPropertiesAsync().done( /* Your success and error handlers */ );
Returns

Remarks

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

See Also

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 )
Windows.Storage.FileProperties.StorageItemContentProperties.getImagePropertiesAsync().done( /* Your success and error handlers */ );
Returns
See Also

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 )
Windows.Storage.FileProperties.StorageItemContentProperties.getMusicPropertiesAsync().done( /* Your success and error handlers */ );
Returns
See Also

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 )
Windows.Storage.FileProperties.StorageItemContentProperties.getVideoPropertiesAsync().done( /* Your success and error handlers */ );
Returns
See Also

RetrievePropertiesAsync(IIterable) RetrievePropertiesAsync(IIterable) RetrievePropertiesAsync(IIterable) RetrievePropertiesAsync(IIterable)

Retrieves the specified properties associated with the item.

public : IAsyncOperation<IMap<Platform::String, Platform::Object>> RetrievePropertiesAsync(IIterable<Platform::String> propertiesToRetrieve)
public IAsyncOperation<IDictionary<string, object>> RetrievePropertiesAsync(IEnumerable<String> propertiesToRetrieve)
Public Function RetrievePropertiesAsync(propertiesToRetrieve As IEnumerable<String>) As IAsyncOperation<IDictionary<string, object>>( Of IMap )
Windows.Storage.FileProperties.StorageItemContentProperties.retrievePropertiesAsync(propertiesToRetrieve).done( /* Your success and error handlers */ );
Parameters
propertiesToRetrieve
IIterable<Platform::String> IEnumerable<String> IEnumerable<String> IEnumerable<String>

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
IAsyncOperation<IMap<Platform::String, Platform::Object>> IAsyncOperation<IDictionary<string, object>> IAsyncOperation<IDictionary<string, object>> IAsyncOperation<IDictionary<string, object>>

When this method completes successfully, it returns a collection (type IMap ) 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. See the remarks under SavePropertiesAsync(IIterable(IKeyValuePair)).

See Also

SavePropertiesAsync() SavePropertiesAsync() SavePropertiesAsync() SavePropertiesAsync()

Saves all properties associated with the item.

public : IAsyncAction SavePropertiesAsync()
public IAsyncAction SavePropertiesAsync()
Public Function SavePropertiesAsync() As IAsyncAction
Windows.Storage.FileProperties.StorageItemContentProperties.savePropertiesAsync().done( /* Your success and error handlers */ );
Returns

No object or value is returned when this method completes.

Remarks

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

See Also

SavePropertiesAsync(IIterable<>>) SavePropertiesAsync(IIterable<>>) SavePropertiesAsync(IIterable<>>) SavePropertiesAsync(IIterable<>>)

Saves the specified properties and values associated with the item.

public : IAsyncAction SavePropertiesAsync(IIterable<IKeyValuePair<Platform::String, Platform::Object>> propertiesToSave)
public IAsyncAction SavePropertiesAsync(IEnumerable<KeyValuePair<String, Object>> propertiesToSave)
Public Function SavePropertiesAsync(propertiesToSave As IEnumerable<KeyValuePair<String, Object>>) As IAsyncAction
Windows.Storage.FileProperties.StorageItemContentProperties.savePropertiesAsync(propertiesToSave).done( /* Your success and error handlers */ );
Parameters
propertiesToSave
IIterable<IKeyValuePair<Platform::String, Platform::Object>> IEnumerable<KeyValuePair<String, Object>> IEnumerable<KeyValuePair<String, Object>> IEnumerable<KeyValuePair<String, Object>>

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

Returns

No object or value is returned when this method completes.

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 with the "System.ExpandoProperties" property name. The expando properties are written using SavePropertiesAsync. 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.

See Also