StorageItemContentProperties 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
struct winrt::Windows::Storage::FileProperties::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() GetDocumentPropertiesAsync()

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

GetImagePropertiesAsync() GetImagePropertiesAsync() GetImagePropertiesAsync() GetImagePropertiesAsync() GetImagePropertiesAsync()

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

GetMusicPropertiesAsync() GetMusicPropertiesAsync() GetMusicPropertiesAsync() GetMusicPropertiesAsync() GetMusicPropertiesAsync()

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

GetVideoPropertiesAsync() GetVideoPropertiesAsync() GetVideoPropertiesAsync() GetVideoPropertiesAsync() GetVideoPropertiesAsync()

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

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

Retrieves the specified properties associated with the item.

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

Saves all properties associated with the item.

SavePropertiesAsync(IIterable<IKeyValuePair<String, Object>>) 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.

See Also