Share via


StorageFile.Properties Proprietà

Definizione

Ottiene un oggetto che fornisce l'accesso alle proprietà correlate al contenuto del file.

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

Valore della proprietà

Oggetto che fornisce l'accesso alle proprietà correlate al contenuto del file.

Implementazioni

Esempio

In questo esempio viene illustrato come recuperare le proprietà del contenuto o le proprietà specificate da un file usando 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
}

Al termine di GetImagePropertiesAsync , imageProperties ottiene un oggetto ImageProperties . Inoltre, dopo il completamento di RetrievePropertiesAsync , extraProperties ottiene un oggetto che contiene le proprietà specificate.

Nell'esempio contiene file un oggetto StorageFile che rappresenta il file per il quale recuperare le proprietà.

Commenti

Nota

Le proprietà che vengono recuperate o impostate usando un gestore di proprietà definito da un'altra app (ad esempio Microsoft Word) potrebbero non essere accessibili. È invece possibile provare a ottenere queste proprietà usando una query di file supportata dall'indice di sistema. Per altre informazioni, vedere QueryOptions.

Per altri esempi di codice sull'accesso alle proprietà, vedere l'esempio di accesso ai file.

Si applica a