0

XMLファイルを保存しようとすると問題が発生しますXMLファイルをAssetsフォルダに保存し、ビルドアクションをAndroid資産に設定しますが、xml.Save( "Q317664.xml") ;パスへのアクセス「/Q317664.xmlは」denied.iが、これはXMLファイルの変更を保存できません

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++); }; 
    } 
} 
} 
+0

参照:http://stackoverflow.com/questions/10562904/is-asset-folder-read-only –

+0

@Morrisonチャンその後、私はそのように私は、xmlファイルを保存する場所XMLファイルの属性を変更することができます –

+0

xmlをファイルとしてアプリケーションのディレクトリに保存することができます。 – Sreeraj

答えて

0

を発生している理由当社は、資産フォルダ内のXMLファイルを編集して保存することができないことを確認していないされています 行が、それは例外System.UnauthorizedAccessExceptionを与えています。アセットフォルダのファイルは、APKに同梱されている静的データを含むファイルです。私たちはそれに書き込むことはできません。 xmlを読み込んでそれを編集し、おそらくファイルをAppのディレクトリに保存することができます。

+0

xmlファイルをアプリケーションディレクトリに保存するにはどうすればいいですか?私はxamarinに新しいです –

+0

@jasonの回答を確認してください – Sreeraj

0
XamarinのAndroidで

var path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); 
var filename = Path.Combine(path, "myFile.xml"); 

File.WriteAllText(filename,xml.ToString()); 
関連する問題