I have data in a dataset. How would I export it into a tab delimited file?
var builder = new StringBuilder()
foreach(var row in dataSet.Tables.First().Rows)
{
foreach(var cell in row.ItemArray)
{
builder.Append(cell.ToString());
if(cell != row.Cells.Last())
builder.Append("\t");
}
builder.Append(Environment.NewLine);
}
var file = new FileStream(filePath);
var writer = new StreamWriter(file);
writer.Write(builder.ToString());
writer.Flush();
writer.Close();
Same problem here. Got a better one for you:
var builder = new StringBuilder();
foreach (DataRow row in dataSet.Tables.First().Rows) {
builder.AppendLine(String.Join("\t", row.ItemArray));
}
File.WriteAllText(filePath, builder.ToString());
Its a bit more compact and (possibly) a tad faster.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With