Skip to content

Instantly share code, notes, and snippets.

@jacks205
Created June 11, 2015 18:58
Show Gist options
  • Save jacks205/b02086405d5f6bbb48d8 to your computer and use it in GitHub Desktop.
Save jacks205/b02086405d5f6bbb48d8 to your computer and use it in GitHub Desktop.
Write to XML File C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace JanteqTestConsoleApplication
{
public class Program
{
static void Main(string[] args)
{
WriteXML();
}
public class Book
{
public String title;
public Author author;
public void Read()
{
}
}
public class Author
{
public String name;
}
public static void WriteXML()
{
Book overview = new Book();
overview.title = "Serialization Overview";
overview.author = new Author();
overview.author.name = "Ian Jackson";
System.Xml.Serialization.XmlSerializer writer =
new System.Xml.Serialization.XmlSerializer(typeof(Book));
var path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "//TestXML.xml";
System.IO.FileStream file = System.IO.File.Create(path);
writer.Serialize(file, overview);
file.Close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment