Jaa


StorageFile.Properties Property

Definition

Gets an object that provides access to the content-related properties of the file.

public:
 property StorageItemContentProperties ^ Properties { StorageItemContentProperties ^ get(); };
StorageItemContentProperties Properties();
public StorageItemContentProperties Properties { get; }
var storageItemContentProperties = storageFile.properties;
Public ReadOnly Property Properties As StorageItemContentProperties

Property Value

The object that provides access to the content-related properties of the file.

Implements

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
}

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

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.

Applies to