How to add headers in my csv file [on hold]

I have the below code where I would like to have Header in first row and output in subsequent rows. I am getting the header in each alternative row. Where should I add the header part. Here the code:

public static void CreatingCsvFiles(string weburl,string StatusNumber, string StatusDescription)         {              if (!System.IO.Directory.Exists(folderPath))             {                  System.IO.Directory.CreateDirectory(folderPath);             }             string delimiter = ",";             string[][] Header = new string[][] { new string[] { "Url of Site", "Status Code :", "Status Description" } };             string[][] output = new string[][] { new string[] {weburl, StatusNumber,  StatusDescription }              };             int length = output.GetLength(0);             StringBuilder sb = new StringBuilder();              //sb.AppendLine(string.Join(delimiter, Header[index]));              for (int index = 0; index < length; index++)                  {                 sb.AppendLine(string.Join(delimiter, Header[index]))                 sb.AppendLine(string.Join(delimiter, output[index]));  }             System.IO.File.AppendAllText(filePath, sb.ToString());          }         } 


Append line to header Array only for first row (when index is 0)

Change your code inside the for loop as below

        if(index == 0)
            sb.AppendLine(string.Join(delimiter, Header[index]));

Category: development Time: 2016-07-29 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.161 (s). 12 q(s)