Use XML serializer with custom extension (C#) | SoloLearn: Learn to code for FREE!


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".

5/5/2018 1:43:29 AM


6 Answers

New Answer


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.


Nice code. Can you post the code of the info class ?


Ok, In a moment I do It, but have you tried To change the Extension?


Not yet. I will try as soon as i can.


Ok thanks, just wait a minute


I am trying, to test it. Can you also post the code of SaveXML.SaveData ?