StorageItemContentProperties Класс

Определение

Предоставляет доступ к свойствам, связанным с содержимым элемента (например, к файлу или папке).

public ref class StorageItemContentProperties sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
class StorageItemContentProperties final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
public sealed class StorageItemContentProperties
Public NotInheritable Class StorageItemContentProperties
Наследование
Object Platform::Object IInspectable StorageItemContentProperties
Атрибуты
Реализации

Требования к Windows

Семейство устройств
Windows 10 (появилось в 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (появилось в v1.0)

Примеры

В этом примере показано, как получить свойства содержимого или указанные свойства из файла с помощью 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
}

После завершения getImagePropertiesAsyncimageProperties получает объект ImageProperties . Кроме того, после завершения RetrievePropertiesAsyncфункция extraProperties получает объект, содержащий указанные свойства (список поддерживаемых свойств можно найти на странице Основные свойства).

В этом примере файл содержит файл StorageFile , представляющий файл, для которого извлекаются свойства.

Комментарии

Объект StorageItemContentProperties можно получить с помощью свойства Properties , доступного для следующих объектов:

Примечание

Свойства, которые получаются или задаются с помощью обработчика свойств, определенного другим приложением (например, Microsoft Word), могут быть недоступны. Вместо этого можно попытаться получить эти свойства с помощью запроса файла, который поддерживается системным индексом. Дополнительные сведения см. в разделе QueryOptions.

Дополнительные примеры кода о доступе к свойствам см. в разделе Пример доступа к файлам.

Методы

GetDocumentPropertiesAsync()

Извлекает свойства документа элемента (например, файл папки).

GetImagePropertiesAsync()

Извлекает свойства изображения элемента (например, файла папки).

GetMusicPropertiesAsync()

Извлекает свойства музыки элемента (например, файл папки).

GetVideoPropertiesAsync()

Извлекает свойства видео элемента (например, файла папки).

RetrievePropertiesAsync(IIterable<String>)

Извлекает указанные свойства, связанные с элементом.

SavePropertiesAsync()

Сохраняет все свойства, связанные с элементом.

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

Сохраняет указанные свойства и значения, связанные с элементом.

Применяется к

См. также раздел