C# 对安装位置的UWP访问被拒绝
我想在InstalledLocation中的文件中创建一个文件,以保存下载的json字符串。但它在System.Private.CoreLib.dll中给出了一个异常,即System.UnauthorizedAccessException。broadFileAccess权限也不起作用,我也尝试了runFullTrust 我在这行中发现了错误C# 对安装位置的UWP访问被拒绝,c#,uwp,C#,Uwp,我想在InstalledLocation中的文件中创建一个文件,以保存下载的json字符串。但它在System.Private.CoreLib.dll中给出了一个异常,即System.UnauthorizedAccessException。broadFileAccess权限也不起作用,我也尝试了runFullTrust 我在这行中发现了错误 var NewFile = await localFolder.CreateFileAsync(@"DownloadedUpdate.json&q
var NewFile = await localFolder.CreateFileAsync(@"DownloadedUpdate.json");
这是我的密码
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using static Osumen_ChatKnoladgeBase.Trainer.ModelHandler;
using Windows.Storage;
using Newtonsoft.Json;
using System.Diagnostics;
using System.Threading.Tasks;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
namespace OsumenChatAI
{
public class UpdateData
{
public object SentFrom { get; set; }
public object Data { get; set; }
}
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class UpdateInfo : Page
{
public UpdateInfo()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var param = (UpdateData)e.Parameter;
var page = param.SentFrom as MainPage;
var NewUpdate = param.Data as Intent[];
Task.Run(async()=> await ApplyUpdate(page, NewUpdate));
}
private async Task ApplyUpdate(MainPage page, Intent[] intents)
{
var localFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
var folderPath = localFolder.Path;
var NewFile = await localFolder.CreateFileAsync(@"DownloadedUpdate.json");
}
}
使用系统;
使用System.Collections.Generic;
使用System.IO;
使用System.Linq;
使用System.Runtime.InteropServices.WindowsRuntime;
使用Windows基金会;
使用Windows。
使用Windows.UI.Xaml;
使用Windows.UI.Xaml.Controls;
使用Windows.UI.Xaml.Controls.Primitives;
使用Windows.UI.Xaml.Data;
使用Windows.UI.Xaml.Input;
使用Windows.UI.Xaml.Media;
使用Windows.UI.Xaml.Navigation;
使用静态Osumen_ChatKnoladgeBase.Trainer.ModelHandler;
使用Windows.Storage;
使用Newtonsoft.Json;
使用系统诊断;
使用System.Threading.Tasks;
//空白页项模板被记录在https://go.microsoft.com/fwlink/?LinkId=234238
门刹台酒店
{
公共类更新数据
{
来自{get;set;}的公共对象
公共对象数据{get;set;}
}
///
///可以单独使用或在框架内导航到的空页。
///
公共密封部分类更新信息:第页
{
公共更新信息()
{
this.InitializeComponent();
}
受保护的覆盖无效OnNavigatedTo(NavigationEventArgs e)
{
var param=(UpdateData)e.Parameter;
var page=param.sentfromas MainPage;
var NewUpdate=param.Data as Intent[];
运行(async()=>等待ApplyUpdate(第页,NewUpdate));
}
专用异步任务应用程序更新(主页面,意图[]意图)
{
var localFolder=Windows.ApplicationModel.Package.Current.InstalledLocation;
var folderPath=localFolder.Path;
var NewFile=await localFolder.CreateFileAsync(@“downloadeUpdate.json”);
}
}
}
我想在InstalledLocation中的文件中创建一个文件,以保存下载的json字符串。但它在System.Private.CoreLib.dll中提供了一个异常System.UnauthorizedAccessException
在UWP平台中,应用程序的目录是只读位置。它用于部署应用程序代码和资产
如果需要访问创建的文件,则无法将其放置在应用程序的InstalledLocation
中。请使用应用程序替换
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
详情请参阅
正式文件