Write Class Data to an XML File in C#.NET



Write Class Data to an XML File in C#.NET

//import namespace 
using System.Xml.Serialization  ;
using Sytem.Xml;
using System.IO; /// 
    /// Owner :Hima
    /// Created  on: 17th Dec 2009
    /// Description : Cheatsheet for Writing Class Data to an XML File 
public class SyntaxHelp
{
   public string Message;
   static void Main()
   {
      SyntaxHelp CSharpNET = new SyntaxHelp();
      CSharpNET.Message = "Welcome to Syntax Help";
    XmlSerializer writer =
         new XmlSerializer(CSharpNET.GetType());
//class data will be written in syntaxhelp.xml
    StreamWriter file =
         new StreamWriter("c:\\syntaxhelp.xml");
      writer.Serialize(file, CSharpNET);
      file.Close();
   }
 }

Share |

 Cant find the page you are looking for?
 Help us to improve by adding the content that you are looking for.
 Leave a feedback
 We look forward to hear your comments and feedback.