Writing to an XML file

mrizoiwe98 66 Reputation points
2021-03-31T07:59:08.387+00:00

Hello, I followed this tutorial on reading XML from a file. But I couldnt find any info how to write to an XML , even create new entries?

My code is similar to this

var assembly = IntrospectionExtensions.GetTypeInfo(typeof(LoadResourceText)).Assembly;  
Stream stream = assembly.GetManifestResourceStream("WorkingWithFiles.LibXmlResource.xml");  
List<Monkey> monkeys;  
using (var reader = new System.IO.StreamReader (stream)) {  
    var serializer = new XmlSerializer(typeof(List<Monkey>));  
    monkeys = (List<Monkey>)serializer.Deserialize(reader);  
}  
var listView = new ListView ();  
listView.ItemsSource = monkeys;  

Thank you

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,294 questions
{count} votes

1 answer

Sort by: Most helpful
  1. JarvanZhang 23,936 Reputation points
    2021-04-01T07:48:25.613+00:00

    I'm trying to write to a file.

    Sorry for the mistake. But embedded resources are read only, we cannot edit the embedded file. To read and write to a file in Xamarin.Forms, try to achieve this on each native platform project.

    Similar issue: https://stackoverflow.com/questions/29395367/xamarin-streamwriter/29395483#29395483

    Related tutorials:
    https://learn.microsoft.com/en-us/xamarin/android/platform/files/
    https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/file-system

    0 comments No comments