Hello Sir,
Please help me with this :
There is an existing CSV file, which has 5 columns and corresponding data. I should validate it and insert a new column at A1. i.e. append at the beginning. I am not able to insert it at beginning. I have used to following code. which insert the data at next line. Kindly help me with this.
Thanks
private void ExportToCSVFilehdr(DataTable dtTable)
{
//adding line
//adding column
StringBuilder sbldr = new StringBuilder();
if (dtTable.Columns.Count != 0)
{
foreach (DataColumn col in dtTable.Columns)
{
sbldr.Append(col.ColumnName + ',');
}
sbldr.Append("\r");
foreach (DataRow row in dtTable.Rows)
{
foreach (DataColumn column in dtTable.Columns)
{
sbldr.Append(row[column].ToString()+ ',');
}
sbldr.Append("\r");
}
}
string test1 = sbldr.ToString();
File.AppendAllText(sourcefilepathhdr, test1);
}