How to rewrite a XML file in monogame?

Hi, I trying to rewrite a xml file in monogame from the code for save the score, but my game crash with this error:
System.UnauthorizedAccessException: Access to the path "/name.xml" is denied.
For write XML file I writed this code:
XMLData.RecordClass data = new XMLData.RecordClass(); data.record = "5"; XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; using (XmlWriter writer = XmlWriter.Create("name.xml", settings)) { Microsoft.Xna.Framework.Content.Pipeline.Serialization.Intermediate.IntermediateSerializer.Serialize(writer, data, null); }

You are trying to save the file to root (note the starting slash ‘/’). Is this your intention? There’s a good chance you need to be admin to write directly to root directory, If you meant to save the file into your current working directory change filename to “name.xml”.

Ok, but if I want to share it for android, is it better to create a folder on android device and put the files there?

1 Like