Click here to Skip to main content
15,904,024 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai,


I am converting the xml files into csv format.But after i converting it into csv the values are not in proper manner.This means values in csv are not in alligned in proper way.How can I solve this.//Below is a sample code for this.

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DataStreams.Xml;
using System.Text;
using DataStreams.Csv;


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

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            using (CsvWriter writer = new CsvWriter("C:/XMLFile1.csv"))
            using (XmlRecordReader reader = new XmlRecordReader("C:/XMLFile1.xml", "CATALOG/PLANT"))
            {
                reader.Columns.Add("COMMON", "COMMON");
                reader.Columns.Add("BOTANICAL", "BOTANICAL");
                reader.Columns.Add("ZONE", "ZONE");
                reader.Columns.Add("LIGHT", "LIGHT");
                reader.Columns.Add("PRICE", "PRICE");
                reader.Columns.Add("AVAILABILITY", "AVAILABILITY");




                writer.Write("COMMON");
                writer.Write("BOTANICAL");
                writer.Write("ZONE");
                writer.Write("LIGHT");
                writer.Write("PRICE");
                writer.Write("AVAILABILITY");
               
                
                writer.EndRecord();

                while (reader.ReadRecord())
                {
                    writer.Write(reader["COMMON"]);
                    writer.Write(reader["BOTANICAL"]);
                    writer.Write(reader["ZONE"]);
                    writer.Write(reader["LIGHT"]);
                    writer.Write(reader["PRICE"]);
                    writer.Write(reader["AVAILABILITY"]);
                  
                    
                    writer.EndRecord();
                }

                reader.Close();
                writer.Close();
            }
        }
    }
}
Posted

1 solution

Please go to this site to find what you are searching for: http://www.csvreader.com/[^]. They build the stuff so you should get better help there.
They also have forums: http://groups.google.com/group/CSVChat/[^].

Best Regards,
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900