Storing a DataTable in a Flatfile
<p>This is the first time I have done any sort of work with flat files.
I need this to be a plain txt file NOT XML.</p>

<p>I have written the following opting for a comma delimited format.</p>

<pre><code>    public static void DataTableToFile(string fileLoc, DataTable dt)
    {
        StringBuilder str = new StringBuilder();
        // get the column headers
        foreach (DataColumn c in dt.Columns)
        {
            str.Append(c.ColumnName.ToString() + ",");
        }
        str.Remove(str.Length-1, 1);
        str.AppendLine();
        // write the data here
        foreach (DataRow dr in dt.Rows)
        {
            foreach (var field in dr.ItemArray)
            {
                str.Append(field.ToString() + ",");
            }
            str.Remove(str.Length-1, 1);
            str.AppendLine();
        }
        try
        {
            Write(fileLoc, str.ToString());
        }
        catch (Exception ex)
        {
            //ToDO:Add error logging
        }
    }
</code></pre>

<p>My question is: Can i do this better or faster?
And <code>str.Remove(str.Length-1, 1);</code> is there to remove the last <code>,</code> which is the only way I could think of.
Any suggestions?</p>
