【发布时间】:2019-09-19 19:39:10
【问题描述】:
我正在开发一个跨平台应用程序(UWP - 目标版本 16299、Android 目标版本 Pie 和 iOS;Visual Studio 2019 - Xamarin.Forms 4.1.0),它需要与在 AppData 中创建的本地数据库文件进行通信。在我尝试将信息导出到 AppData 之外的另一个文件之前,一切都很有趣。 我尝试了很多事情都没有成功,我很好奇为什么它对你有用而不对我有用。
这是我测试过的最新代码,与其他代码相似,结果相同:
抛出异常:System.Private.CoreLib.dll 中的“System.UnauthorizedAccessException”
using Plugin.FilePicker;
using Plugin.FilePicker.Abstractions;
using Plugin.Permissions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.PlatformConfiguration;
namespace Testing
{
[DesignTimeVisible(false)]
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private Plugin.FilePicker
.Abstractions.FileData file;
private async void ImportBtn_Clicked(object sender, EventArgs e)
{
try
{
file = await CrossFilePicker.Current.PickFile();
}
catch (Exception ex)
{
}
file.FileName = "rooms.jpg";
file.FilePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
await CrossFilePicker.Current.SaveFile(file);
}
private void ExportBtn_Clicked(object sender, EventArgs e)
{
{
string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string localFilename = "download.txt";
string localPath = Path.Combine(documentsPath, localFilename);
try
{
File.Create(localPath);
}
catch(Exception ex)
{ Debug.WriteLine(ex); }
Debug.WriteLine(localPath);
}
}
}
}
我想提一下,所有功能都已勾选,在拼命尝试让某些东西正常工作时,import_clicked 按预期工作,尝试的文件夹(个人、音乐、图片、共享)是空的。
【问题讨论】:
-
你用哪个操作系统测试它?
-
Windows 10 专业版
-
我的意思是移动操作系统 :)
-
@iSpain17 Android 9.0 - API 28。从 Windows 10 模拟。它不会抛出错误,但位置无法访问 [0:] /data/user/0/com.companyname.testing /files/download.txt
标签: c# xamarin.forms unauthorizedaccessexcepti