【发布时间】:2021-06-19 10:17:13
【问题描述】:
这是我遇到问题的代码的 sn-p:
public OpenPage(string filePath, int? index, object jobject)
{
InitializeComponent();
File.SetAttributes(filePath, FileAttributes.Normal); // Here is where error in title occurs
var readText = File.ReadAllText(filePath); // Also occurs here
DisplayAlert("Alert", readText, "Ok");
}
我正在创建一个 UWP Xamarin.Forms 应用程序,该应用程序需要从选定目录(C: 驱动器上的任何内容)读取文件。虽然当我没有从本地缓存/AppData 中选择文件时,标题中出现错误。
查看 StackOverflow 中的其他类似帖子(例如 Why is access to the path denied?)非常有助于了解有关该主题的更多信息,尽管有关此错误的许多问题都已过时。
在上面的帖子中,有人说不能将目录作为 File.ReadAllText() 的参数传递。
有什么解决办法吗?我需要访问 C: 驱动器上的文件。作为参考,我调试时构造函数中的filePath是“C:\Users\ianpc\Desktop\config file clones\te0_ptt_wog.json”。
【问题讨论】:
标签: c# xamarin.forms uwp xamarin.essentials