【发布时间】:2016-04-17 11:37:06
【问题描述】:
我将 Xml 文件保存在 Assets 文件夹中并将 Build Action 设置为 Android Assets,当我尝试将更改保存到 xml 文件时,它会给出异常 System.UnauthorizedAccessException: Access to the path "/Q317664.xml" is denied.i不知道为什么会发生这个异常,请帮助我
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using System.IO;
using System.Reflection;
using Android.Content.Res;
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace App17
{
[Activity(Label = "App17", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
int count = 1;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
var xml = XDocument.Load(Assets.Open("Q317664.xml"));
var node = xml.Descendants("Book").FirstOrDefault(cd => cd.Attribute("Id").Value == "1");
node.SetAttributeValue("ISBN", "new");
xml.Save("Q317664.xml");
// Button button = FindViewById<Button>(Resource.Id.MyButton);
// button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
}
}
}
【问题讨论】:
标签: c# android xml xamarin xamarin.android