StorageFile.Properties Properti

Definisi

Mendapatkan objek yang menyediakan akses ke properti file terkait konten.

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

Nilai Properti

Objek yang menyediakan akses ke properti file terkait konten.

Penerapan

Contoh

Contoh ini menunjukkan cara mengambil properti konten atau properti tertentu dari file menggunakan 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
}

Setelah GetImagePropertiesAsync selesai, imageProperties mendapatkan objek ImageProperties . Selain itu, setelah RetrievePropertiesAsync selesai, extraProperties mendapatkan objek yang berisi properti yang ditentukan.

Dalam contoh, file berisi StorageFile yang mewakili file untuk mengambil properti.

Keterangan

Catatan

Properti yang didapatkan atau diatur menggunakan handler properti yang ditentukan oleh aplikasi lain (seperti Microsoft Word) mungkin tidak dapat diakses. Sebagai gantinya, Anda bisa mencoba mendapatkan properti ini menggunakan kueri file yang didukung oleh indeks sistem. Untuk informasi selengkapnya, lihat QueryOptions.

Untuk sampel kode lainnya tentang mengakses properti, lihat Sampel akses file.

Berlaku untuk