C# 使用C在metro应用程序中设置文件夹权限#

C# 使用C在metro应用程序中设置文件夹权限#,c#,xaml,windows-8,windows-runtime,C#,Xaml,Windows 8,Windows Runtime,我正在使用Windows8版本预览和C#(VS2012)开发metro应用程序,我一直坚持异步创建文件。我正在使用以下代码在文件夹中创建文件 StorageFolder storageFolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Data"); StorageFile File= await storageFolder.CreateFile

我正在使用Windows8版本预览和C#(VS2012)开发metro应用程序,我一直坚持异步创建文件。我正在使用以下代码在文件夹中创建文件

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);
其中“Data”是foldername,“result”是text,“DataFile”是filename,但我在这一行得到了
unauthorizedAccessException

 StorageFile File= await storageFolder.CreateFileAsync("DataFile",CreationCollisionOption.ReplaceExisting); 

我知道我的文件夹“数据”是只读的,但如何将文件夹属性更改为可写,我也尝试了
storageFolder.Attributes
properties,但它是只读属性。

您在InstalledLocation中没有写访问权限。这基本上就像写入“程序文件”(它实际上是“程序文件”中的一个文件夹),据我记忆所及,由于安全原因,它早在Vista就被阻止了


您应该改为尝试写入ApplicationData.Current.LocalFolder。

为什么不能在应用程序的存储中创建数据文件?为什么需要在包的数据目录中创建它?