若您有這樣的需求,想要將某個在 Isolated Storage 內的檔案,設定成為唯讀的屬性,此時,您會需要用到:
StorageFile.Properties
取得物件,用以存取檔案的內容相關屬性。
StorageFile.Properties
取得物件,用以存取檔案的內容相關屬性。
當取得了 StorageFile.Properties屬性後,他是個屬於 StorageItemContentProperties 類型的物件,代表了 提供檔案之內容相關屬性存取權的物件。
參考下列程式碼,您可以設定檔案為唯讀屬性
String key = "System.FileAttributes";
UInt32 FILE_ATTRIBUTES_READONLY = 1;
var pix = Windows.Storage.KnownFolders.PicturesLibrary;
var file = await pix.GetFileAsync("test.jpg");
String[] retrieveList = new String[] { key };
var props = await file.Properties.RetrievePropertiesAsync(retrieveList);
if (props != null)
{
var temp = (UInt32)props[key] | FILE_ATTRIBUTES_READONLY;
props[key] = temp;
}
else
{
props = new Windows.Foundation.Collections.PropertySet();
props.Add(key, FILE_ATTRIBUTES_READONLY);
}
await file.Properties.SavePropertiesAsync(props);
沒有留言:
張貼留言