尝试复制和XML文件时,C#Access被拒绝

时间:2017-07-14 04:29:02

标签: c# visual-studio xamarin mobile access

c#问题在这里。尝试移动xml文件时,我一直拒绝访问。我知道问题是它正在创建一个没有管理员权限的临时XML文件,我尝试使用require admin = true行编辑appmanifest无济于事。我还尝试在程序外设置权限并以管理员身份运行visual studio。

Link to the pastebin code.
https://pastebin.com/M7dRTXHY

enter image description here

我实际上昨天使用完全不同的代码得到了答案,但我的老师说我必须这样做。我花了好几个小时试图调试这个并且正在失去理智。

这也是一个Windows 10手机应用程序,不确定是否会改变任何内容。

我意识到有一百万个问题与此类似,但我无法解决任何问题。

这是我直接从我的课程中学习的确切教程。 enter image description here

1 个答案:

答案 0 :(得分:1)

使用StorageFile进行移动/复制/删除等操作:

private async void Grid_Loading(FrameworkElement sender, object args)
{
   Windows.ApplicationModel.Package package = Windows.ApplicationModel.Package.Current;
   StorageFolder installedLocation = package.InstalledLocation;
   StorageFolder targetLocation = ApplicationData.Current.LocalFolder;

   var targetFile = await installedLocation.GetFileAsync("Contacts.xml");
   await targetFile.MoveAsync(targetLocation);
   TARGETFILEPATH = ApplicationData.Current.LocalFolder.Path.ToString() + "\\Contacts.xml";
   loadContacts();
}

有关StorageFiles here的更多信息。