B
Brendan Miller
Hi,
I have been having a problem writing the contents of a dataset to a .csv
file. When I write to a .csv file and open it with either Excel or Wordpad
the "french" characters are wrong. When I open the file with notepad the
characters are displayed correctly. e.g. in notepad: École, in
Wordpad/Excel: Ã?cole. Having the user import a text file and format it
themselves is not an option. The output must be .csv.
The function I was using is as follows:
private void CreateFile(string path, DataSet ds, string strXYZ, int
language)
{
string strfname = \\2004 + strXYZ + "_" + language;
string strext = ".txt";
StreamWriter file = new System.IO.StreamWriter(path + strfname +
strext);
try
{
foreach (DataTable dt in ds.Tables)
{
//write column headers
foreach (DataColumn dc in dt.Columns)
{
file.Write(dc.Caption.ToString() + ",");
}
//write each row
foreach (DataRow dr in dt.Rows)
{
foreach (DataColumn dc in dt.Columns)
{
if (dc.Caption == "SomeColumnName")
{
string strBarcode;
strBarcode = dr[dc].ToString();
file.Write(strBarcode);
}
else
{
file.Write(dr[dc] + ",");
}
}
file.WriteLine();
Application.DoEvents();
}
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
file.Flush();
file.Close();
}
Thanks in advance.
Brendan
I have been having a problem writing the contents of a dataset to a .csv
file. When I write to a .csv file and open it with either Excel or Wordpad
the "french" characters are wrong. When I open the file with notepad the
characters are displayed correctly. e.g. in notepad: École, in
Wordpad/Excel: Ã?cole. Having the user import a text file and format it
themselves is not an option. The output must be .csv.
The function I was using is as follows:
private void CreateFile(string path, DataSet ds, string strXYZ, int
language)
{
string strfname = \\2004 + strXYZ + "_" + language;
string strext = ".txt";
StreamWriter file = new System.IO.StreamWriter(path + strfname +
strext);
try
{
foreach (DataTable dt in ds.Tables)
{
//write column headers
foreach (DataColumn dc in dt.Columns)
{
file.Write(dc.Caption.ToString() + ",");
}
//write each row
foreach (DataRow dr in dt.Rows)
{
foreach (DataColumn dc in dt.Columns)
{
if (dc.Caption == "SomeColumnName")
{
string strBarcode;
strBarcode = dr[dc].ToString();
file.Write(strBarcode);
}
else
{
file.Write(dr[dc] + ",");
}
}
file.WriteLine();
Application.DoEvents();
}
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
file.Flush();
file.Close();
}
Thanks in advance.
Brendan