i have a listbox, and i want to save the items into an xml file.
this is the code to save:
try
{
XmlSerializer serializer = new XmlSerializer(typeof(string));
TextWriter tw = new StreamWriter("C:\\Users\\Lifebook\\Desktop\\Usage Profiles.txt");
for (int i = 0; i <= lstUsageProfile.Items.Count - 1; i++)
{
serializer.Serialize(tw, lstUsageProfile.Items[i].ToString());
}
tw.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error saving");
}
This is the output of the xml
<string><node1></string>
this line is repeated for every node in the list box.
to save them it's no problem, but then i want to load them (for the next user who is working on the program)
but i can't load them up and put them back in the list box and removing the xml tags created by default.
pls help.
after that link, i improved my code to:
XmlSerializer deserializer = new XmlSerializer(typeof(List<string>));
TextReader textReader = new StreamReader("C:\\Users\\Lifebook\\Desktop\\Usage Profiles.txt");
List<string> up;
up = (List<string>)deserializer.Deserialize(textReader);
textReader.Close();
lstUsageProfile.Items.Add(up);</string></string></string>
and i'm getting this error
There is an error in XML document (2, 2).