I've attached a screenshot of the returned CSV file to show the issue:
These are supposed to be a single column having URLs pointing to a geo coordinate. After looking through your code I understood the issue: when there are commas within quotes, it does not work and the entire string breaks.
public static string ToDelimitedFile(this DataTable dataTable, char delimiter, bool inQuote)
{
StringBuilder content = new StringBuilder();
string lastColumn = dataTable.Columns[dataTable.Columns.Count - 1].ColumnName;
foreach (DataColumn dc in dataTable.Columns)
{
content.Append(dc.ColumnName);
if (dc.ColumnName != lastColumn)
content.Append(delimiter);
}
int i = 0;
foreach (DataRow dr in dataTable.Rows)
{
content.Append(Environment.NewLine);
foreach (DataColumn dc in dataTable.Columns)
{
if (inQuote)
content.Append('"' + dr[dc.ColumnName].ToString() + '"');
else
content.Append(dr[dc.ColumnName].ToString());
if (dc.ColumnName != lastColumn)
content.Append(delimiter);
}
}
return content.ToString();
}
I've attached a screenshot of the returned CSV file to show the issue:
These are supposed to be a single column having URLs pointing to a geo coordinate. After looking through your code I understood the issue: when there are commas within quotes, it does not work and the entire string breaks.