Share via


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
}

GetImagePropertiesAsync完成之後,imageProperties會取得ImageProperties物件。 此外, 在 RetrievePropertiesAsync 完成之後, extraProperties 會取得包含指定屬性的物件, (可以在 [核心屬性] 頁面上 找到支援的屬性清單) 。

在此範例中, 檔案 包含 StorageFile ,代表要擷取屬性的檔案。

備註

您可以使用下列物件上可用的 Properties 屬性,取得 StorageItemContentProperties 物件:

注意

使用其他應用程式所定義的屬性處理常式取得或設定的屬性, (例如 Microsoft Word) 可能無法存取。 相反地,您可以使用系統索引所支援的檔案查詢來嘗試取得這些屬性。 如需詳細資訊,請參閱 QueryOptions

如需有關存取屬性的詳細資訊程式碼範例,請參閱 檔案存取範例

方法

GetDocumentPropertiesAsync()

擷取專案的檔案屬性 (,例如資料夾) 的檔案。

GetImagePropertiesAsync()

擷取專案 (影像屬性,例如資料夾) 的檔案。

GetMusicPropertiesAsync()

擷取專案 (的音樂屬性,例如資料夾) 的檔案。

GetVideoPropertiesAsync()

擷取專案 (的視訊屬性,例如資料夾) 的檔案。

RetrievePropertiesAsync(IIterable<String>)

擷取與專案相關聯的指定屬性。

SavePropertiesAsync()

儲存與專案相關聯的所有屬性。

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

儲存與專案相關聯的指定屬性和值。

適用於

另請參閱