+ 1
Use XML serializer with custom extension (C#)
I want to save data in a file with the XML Serializer, and that the file with the saved information has a custom file extension, such as "abc".
6 Respuestas
0
This is the code I tried
`try
{
Information info = new Information ();
info.Data = textboxdata1.Text;
info.Data2 = textboxdata2.Text;
info.Data3 = textboxdata3.Text;
SaveXML.SaveData (info, "data.xml");
}
catch (Exception ex)
{
MessageBox.Show (ex.Message);
}
}
private void Form1_Load (object sender, EventArgs e)
{
if (File.Exist ("data.xml"))
{
XmlSerializer xs = new XmlSerializer (typeof (Information));
FileStream read = new FileStream ("data.xml, FileMode.Open, FileAccess.Read, FileShare.Read);
Information info = (Information) xs.Deserialize (read);
textboxData1.Text = info.Data1;
textboxdata2.Text = info.Data2;
textboxdata3.Text = info.Data3; `
Specifically, I want to know if you can replace the "xml" ending with a custom "abc" ending, and that it still have the same values and that it works as such. Just like here
SaveXML.SaveData (info, "data.xml");
Thanks for your attention.
0
Nice code. Can you post the code of the info class ?
0
Ok, In a moment I do It, but have you tried To change the Extension?
0
Not yet. I will try as soon as i can.
0
Ok thanks, just wait a minute
0
I am trying, to test it.
Can you also post the code of SaveXML.SaveData ?