Home
Manage Your Code
Snippet: Write (Serialize) XML (C#)
Title: Write (Serialize) XML Language: C#
Description: Writes the class to a file by serialized the member variable into xml data. Views: 547
Author: Clint Brown Date Added: 10/3/2007
Copy Code  
1		public bool Write(string Filename)
2		{
3			try
4			{
5				XmlSerializer ser = new XmlSerializer(typeof(XMLProf));
6				TextWriter tw = new StreamWriter(Filename, false);
7				ser.Serialize(tw, this);
8				tw.Close();
9			}
10			catch (Exception ex)
11			{
12				MessageBox.Show(ex.Message);
13				return true;
14			}
15			return false;
16		}
Notes
In the line ser.Serialize(tw, this); the 'this' must be changed to the member variable of the instance of the class be serialized and typecast. In this case the class is XMLProf.