BasicProperties Класс

Определение

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

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
Наследование
Object Platform::Object IInspectable BasicProperties
Атрибуты
Реализации

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

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

Примеры

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

После завершения basicPropertiesgetBasicPropertiesAsync получает объект BasicProperties.

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

Комментарии

Доступ к объекту BasicProperties можно получить асинхронно с помощью метода GetBasicPropertiesAsync элемента (например, файла папки) или синхронно с помощью свойства BasicProperties , если он доступен.

Объект BasicProperties можно получить с помощью любого из следующих методов и свойств:

Свойства

DateModified

Возвращает метку времени последнего изменения файла.

ItemDate

Возвращает наиболее релевантную дату для элемента.

Size

Возвращает размер файла в байтах.

Методы

RetrievePropertiesAsync(IIterable<String>)

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

SavePropertiesAsync()

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

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

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

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

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