Jaa


BasicProperties Class

Definition

Provides access to the basic properties, like the size of the item or the date the item was last modified, of the item (like a file or folder).

public ref class BasicProperties sealed : IStorageItemExtraProperties
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
class BasicProperties final : IStorageItemExtraProperties
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
public sealed class BasicProperties : IStorageItemExtraProperties
Public NotInheritable Class BasicProperties
Implements IStorageItemExtraProperties
Inheritance
Object Platform::Object IInspectable BasicProperties
Attributes
Implements

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

Examples

The File access sample demonstrates how to retrieve properties of a file, including basic properties like Size and DateModified.

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

        // Get basic properties
        BasicProperties basicProperties = await file.GetBasicPropertiesAsync();
        outputText.AppendLine("File size: " + basicProperties.Size + " bytes");
        outputText.AppendLine("Date modified: " + basicProperties.DateModified);

        // 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
}

After GetBasicPropertiesAsync completes, basicProperties gets a BasicProperties object.

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

Remarks

You can access a BasicProperties object asynchronously using the GetBasicPropertiesAsync method of an item (like a file of folder), or synchronously using the BasicProperties property if it is available.

You can get a BasicProperties object using any of the following methods and properties:

Properties

DateModified

Gets the timestamp of the last time the file was modified.

ItemDate

Gets the most relevant date for the item.

Size

Gets the size of the file in bytes.

Methods

RetrievePropertiesAsync(IIterable<String>)

Retrieves the specified properties associated with the item.

SavePropertiesAsync()

Saves all properties associated with the item.

SavePropertiesAsync(IIterable<KeyValuePair<String,Object>>)

Saves the specified properties and values associated with the item.

Applies to

See also