Hi I'm using the below code to export the data in queryResult:
private void btnDownload_Click(object sender, EventArgs e)
{
var queryResult = from s in context.Contacts
join c in context.Address on s.ContactID equals c.Contact.ContactID
select new
{
s.FirstName,
s.LastName,
s.ContactNumber,
c.Address1,
c.Mortgage,
c.RemainingMortgage,
c.Rent,
c.Period,
c.RentArrears,
c.Rates,
c.RateArrears,
c.RatesUpToDate,
c.Repairs
};
CsvFileDescription outputFileDescription = new CsvFileDescription
{
SeparatorChar = '\t',
FirstLineHasColumnNames = true,
FileCultureName = "en-GB"
};
CsvContext cc = new CsvContext();
cc.Write(
queryResult,
"Houses.csv",
outputFileDescription);
}
I've a couple of questions regarding the created CSV file:
1)my header col has the column names yet in the outputted CSV they are listed together in Cell A1 as 1 string
2)The address field on the form is a rich text box so when an address with return key presses is entered this splits the outputted string in the CSV file (one way to stop this is to have separate text boxes for each part of the address but is there a workaround for my question?)
3) Instead of writing the file to a file directory can I display it to the user once all data has been written successfully?