简体   繁体   中英

C# Access Denied when trying to Copy and XML file

c# question here. I keep getting access is denied when trying to move an xml file. I know the problem is that it is creating a temporary XML file with no admin privileges which its needs, and I have tried editing the appmanifest with the require admin = true line to no avail. I have also tried setting the permissions outside the program and running visual studio as an admin.

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

在此处输入图像描述

I actually got an answer for this using completely different code yesterday but my teacher said I must do it this way. I have spent hours trying to debug this and am losing my mind.

It is a windows 10 phone application as well, not sure if that changes anything.

I realise there is a million and one other questions similar to this but I cannot get anything to work.

This is the exact tutorial I was following taken straight from my course. 在此处输入图像描述

Use the StorageFile for the move/copy/delete etc operations:

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();
}

more on StorageFiles here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM