There are probably other ways of doing this, but the easiest way I found is to first store your textbox data in a class, then use an XmlSerializer to write the data to an xml file. The class that you write the data to must be serializable. I'm not sure of all the requirements for that but I think that you need to have an empty constructor and all data must be publically accessable. Here is an example:
class MyClass
{
string m_data1, m_data2;
public MyClass()
{
m_data1 = "";
m_data2 = "";
}
public string Data1
{
get
{
return m_data1;
}
set
{
m_data1 = value;
}
}
public string Data2
{
get
{
return m_data2;
}
set
{
m_data2 = value;
}
}
}
When you click Save, you can write your data to a class like this. Then when you want to serialize, you can do this:
private void HandleSaveButtonClick( object sender, EventArgs args )
{
// Build your object
MyClass mClass = new MyClass();
mClass.Data1 = m_textbox1.Text;
mClass.Data2 = m_textbox2.Text;
//--------------------------------------------------------------------------------------
// Open a file stream (delete the file first so we don't get mangled data when we write)
//--------------------------------------------------------------------------------------
string path = "blah/mypath/blah.xml"
File.Delete( path );
FileStream fs = new FileStream( path, FileMode.OpenOrCreate, FileAccess.Write );
//-------------------------------------
// Serialize mClass to a file
//-------------------------------------
XmlSerializer serializer = new XmlSerializer( typeof( MyClass ) );
serializer.Serialize( fs, mClass );
fs.Close();
}
Hope that helps,
Jordan