Click here to Skip to main content
15,915,873 members
Home / Discussions / C#
   

C#

 
QuestionGood resources for beginning Visual C#? Pin
quicksnap6-Aug-09 4:23
quicksnap6-Aug-09 4:23 
AnswerRe: Good resources for beginning Visual C#? Pin
laziale6-Aug-09 4:28
laziale6-Aug-09 4:28 
GeneralRe: Good resources for beginning Visual C#? Pin
quicksnap6-Aug-09 4:32
quicksnap6-Aug-09 4:32 
AnswerRe: Good resources for beginning Visual C#? Pin
Cracked-Down6-Aug-09 19:17
Cracked-Down6-Aug-09 19:17 
Questioncreating csv from xml file in c# Pin
laziale6-Aug-09 4:00
laziale6-Aug-09 4:00 
AnswerRe: creating csv from xml file in c# Pin
Fayu6-Aug-09 5:27
Fayu6-Aug-09 5:27 
GeneralRe: creating csv from xml file in c# Pin
laziale6-Aug-09 5:33
laziale6-Aug-09 5:33 
GeneralRe: creating csv from xml file in c# Pin
Fayu6-Aug-09 6:35
Fayu6-Aug-09 6:35 
The easiest way is to dump the xml into a dataset and enumerate throught the rows and write to file. Look at the code below.

        public static void SaveXmlToFile(string xml, string output)
        {
            string seperator = ";";
            DataSet ds = new DataSet();
            DataTable bzTable = null;
            DataTable adTable = null;
            DataTable cntTable = null;
            StringBuilder sb = new StringBuilder();

            //Dump xml into dataset
            using (MemoryStream ms = new MemoryStream())
            {
                using (StreamWriter sw = new StreamWriter(ms))
                {
                    sw.BaseStream.Seek(0, SeekOrigin.Begin);
                    sw.Write(xml);
                    sw.Flush();
                    sw.BaseStream.Seek(0, SeekOrigin.Begin);
                    ds.ReadXml(sw.BaseStream);
                }
            }

            //Set tables after ds has been built
            bzTable = ds.Tables["Business"];
            adTable = ds.Tables["Address"];
            cntTable = ds.Tables["Contact"];

            //Read Business table
            foreach (DataRow bzRow in bzTable.Rows)
            {
                //Get Business_id; Generated when dumping data into ds
                int curBzId = Convert.ToInt32(bzRow["Business_Id"]);

                //Enumerate though business tables and write data into string builder
                foreach (DataColumn bzCol in bzTable.Columns)
                {
                    sb.Append(string.Format("{0}{1}", bzRow[bzCol].ToString(), seperator));
                }

                //Filter Address column for curBzId and write values to string builder
                foreach (DataRow adRow in adTable.Select(string.Format("[Business_Id]={0}", curBzId)))
                {
                    foreach (DataColumn adCol in adTable.Columns)
                    {
                        sb.Append(string.Format("{0}{1}", adRow[adCol].ToString(), seperator));
                    }
                }

                //Filter Contact column for curBzId and write values to string builder
                foreach (DataRow cntRow in cntTable.Select(string.Format("[Business_Id]={0}", curBzId)))
                {
                    foreach (DataColumn cntCol in cntTable.Columns)
                    {
                        sb.Append(string.Format("{0}{1}", cntRow[cntCol].ToString(), seperator));
                    }
                }

                //Row completed.  Add new line constant
                sb.Append(Environment.NewLine);
            }

            //Save file
            using (StreamWriter sw = new StreamWriter(output))
            {
                sw.BaseStream.Seek(0, SeekOrigin.Begin);
                sw.Write(sb.ToString());
                sw.Flush();
            }
ds.Dispose();
bzTable.Dispose();
adTable.Dispose();
cntTable.Dispose();
        }

GeneralRe: creating csv from xml file in c# Pin
laziale6-Aug-09 8:34
laziale6-Aug-09 8:34 
AnswerRe: creating csv from xml file in c# Pin
PIEBALDconsult6-Aug-09 12:43
mvePIEBALDconsult6-Aug-09 12:43 
QuestionTransparent control, C# Pin
TwilightEva6-Aug-09 3:00
TwilightEva6-Aug-09 3:00 
AnswerRe: Transparent control, C# Pin
Super Lloyd6-Aug-09 3:07
Super Lloyd6-Aug-09 3:07 
GeneralRe: Transparent control, C# Pin
TwilightEva6-Aug-09 3:12
TwilightEva6-Aug-09 3:12 
GeneralRe: Transparent control, C# Pin
Super Lloyd6-Aug-09 3:19
Super Lloyd6-Aug-09 3:19 
GeneralRe: Transparent control, C# Pin
TwilightEva6-Aug-09 5:11
TwilightEva6-Aug-09 5:11 
GeneralRe: Transparent control, C# Pin
Super Lloyd6-Aug-09 5:17
Super Lloyd6-Aug-09 5:17 
QuestionHow to extract text from a PDF file using c#? Pin
svt gdwl6-Aug-09 2:52
svt gdwl6-Aug-09 2:52 
AnswerRe: How to extract text from a PDF file using c#? Pin
Super Lloyd6-Aug-09 3:24
Super Lloyd6-Aug-09 3:24 
GeneralRe: How to extract text from a PDF file using c#? Pin
Amangang6-Aug-09 5:13
Amangang6-Aug-09 5:13 
GeneralRe: How to extract text from a PDF file using c#? Pin
Super Lloyd6-Aug-09 5:19
Super Lloyd6-Aug-09 5:19 
QuestionSlow rendering when adding usercontrol to panel Pin
Fayu6-Aug-09 2:52
Fayu6-Aug-09 2:52 
AnswerRe: Slow rendering when adding usercontrol to panel Pin
Blubbo6-Aug-09 2:59
Blubbo6-Aug-09 2:59 
GeneralRe: Slow rendering when adding usercontrol to panel Pin
DaveyM696-Aug-09 3:48
professionalDaveyM696-Aug-09 3:48 
GeneralRe: Slow rendering when adding usercontrol to panel Pin
Blubbo6-Aug-09 6:14
Blubbo6-Aug-09 6:14 
GeneralRe: Slow rendering when adding usercontrol to panel Pin
DaveyM696-Aug-09 11:54
professionalDaveyM696-Aug-09 11:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.