I’m developing metro app using Windows 8 release preview and C#(VS 2012), I’m stuck with creating file Asynchronously. I’m using following code to create file in folder
StorageFolder storageFolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Data");
StorageFile File= await storageFolder.CreateFileAsync("DataFile",CreationCollisionOption.ReplaceExisting);
await Windows.Storage.FileIO.WriteTextAsync(File, result);
Where “Data” is foldername,”result” is text and “DataFile” is filename, But I got UnAuthorisedAccessException at this line
StorageFile File= await storageFolder.CreateFileAsync("DataFile",CreationCollisionOption.ReplaceExisting);
I understand that my folder “Data” is read only, but how do I change the folder attribute to writable, I also tried storageFolder.Attributes property but it is readonly property.
You do not get write access in the InstalledLocation. It would basically be like writing to “Program Files” (it actually is a folder inside of “Program Files”), which as far as I remember was blocked as far back as Vista for security reasons.
You should try writing to ApplicationData.Current.LocalFolder instead.