Q:

c# saving strings to CSV file create blank inital row

I am using the following code to save data to a CSV file, but then I open the file, the initial row (row 1) is blank.
If I remove any of the 

Environment.NewLine

statements, I either loose the column titles, or the data gets appended to them.
string CSVTitle = "Code,ID,Name,Booked" + Environment.NewLine;
string LineOneData = Code + "," + id + "," + Booked;
string csvFile = string.Join(CSVTitle, Environment.NewLine, LineOneData);

could someone advise me on how I have managed to create a blank first line, and on how to remove it ?
Thanks

A:

Trim the leading Environment.NewLine:
string csvFile = string.Join(CSVTitle, Environment.NewLine, LineOneData).TrimStart();

Or don't use Join at all:
string CSVTitle = "Code,ID,Name,Booked";
string LineOneData = Code + "," + id + "," + Booked;
string csvFile = string.Format("{0}{1}{2}", CSVTitle, Environment.NewLine, LineOneData);

A:

The string.Join() method will concatenate a set of strings using a specified delimiter. In your case you specified CSVTitle as delimiter, and provided "Environment.NewLine, LineOneData" as set of strings to concatenate.
To fix the issue in your case you can simply re-order the arguments passed to string.Join(), and get rid of the first Environment.NewLine you're adding in the first line. So your solution might look something like this:
string CSVTitle = "Code,ID,Name,Booked";
string LineOneData = Code + "," + id + "," + Booked;
string csvFile = string.Join(Environment.NewLine, CSVTitle, LineOneData);

This way it will use "CSVTitle, LineOneData" as set of strings to concatenate, and delmit these strings by the Environment.NewLine string.

