Tuesday, 7 February 2012

Convert Enum to Xml in C# Dot net


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.IO;

public partial class GridViewEdit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public enum name
    {
        Sanjay,
        Satyajeet,
        Satyabrata,
        Manas,
        Deepak
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        DataTable dt = new DataTable("NM");
        dt.Columns.Add("ID");
        dt.Columns.Add("Name");
        int i = 0;
        foreach (string s in Enum.GetNames(typeof(name)))
        {
            DataRow dr = dt.NewRow();
            dr["ID"] = i;
            dr["Name"] = s;
            dt.Rows.Add(dr);
            i++;
        }
        DataSet ds = new DataSet();
        ds.Tables.Add(dt);
        ds.WriteXml(Server.MapPath("XML\\myFile.xml"));
    }
}

No comments:

Post a Comment