使用c#写入windows存储中的文件? [英] Access file in windows store using c# to write?

查看:128
本文介绍了使用c#写入windows存储中的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中。我在文件夹Data / history.txt中创建了一个文件。我可以通过使用代码访问history.txt来读取它中的某些东西:

StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(ms-appx:///Data/history.txt)) );

StreamReader reader = new StreamReader(await file.OpenStreamForReadAsync());

while(!reader.EndOfStream)

{

string s = reader.ReadLine();

}



但我不能写任何东西给这个文件,使用代码:

StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(ms-appx:///Data/history.txt));

等待Windows.Storage.FileIO.AppendTextAsync(文件,文本+''\ n'');



构建后,我收到了有关访问文件的信息:

访问被拒绝。 (来自HRESULT的异常:0x80070005(E_ACCESSDENIED))

如果您尝试访问文件或注册表项,请确保它不是只读的。

确保您有足够的权限访问这个资源...



任何人都可以帮助我,PLZ ??

感谢您的时间!!

In my project. I created a file in folder "Data/history.txt". I can access history.txt to read somethings from it, by using code:
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Data/history.txt"));
StreamReader reader = new StreamReader(await file.OpenStreamForReadAsync());
while (!reader.EndOfStream)
{
string s = reader.ReadLine();
}

but I can''t write any thing to this file, by using code:
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Data/history.txt"));
await Windows.Storage.FileIO.AppendTextAsync(file, text + ''\n'');

After build, I received an info about access file:
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
If you are attempting to access a file or registry key, make sure it is not read-only.
Make sure you have sufficient privileges to access this resource...

Can anyone help me, plz??
Thanks for your time!!

推荐答案

拒绝访问的哪一部分难以理解?您最好阅读各种位置以及它们在Windows应用商店应用中的用途,这里 [ ^ ]。



您指定的路径位于应用程序安装位置下,该位置始终为READ ONLY。你不能把数据写到这个位置。您必须使用更加用户友好的(就安全性而言)位置来编写数据,例如ms-appdata:///。
What part of "Access Denied" is difficult to understand?? You better read up on the various locations and what they''re for in Windows Store apps, here[^].

The path you specified is under the application install location, which is always READ ONLY. You can''t write data to this location. You have to use a more user-friendly (as far as security is concerned) location to write your data, like "ms-appdata:///".


这篇关于使用c#写入windows存储中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆