Export to CSV problem



Hi everyone,

I am facing a problem in exporting CSV file.I able to export it
properly in IE7 bbut in Mozila it seems the file name is changed and
an extra , is added in the file name.say if the file name is
"Report .csv" in mozila it becomes Report .csv," .I am writting the
code below.

private void ExportToCsv(DataSet ds)
{

try
{
string header = string.Empty;
string body = string.Empty;
string record = string.Empty;
foreach (DataColumn col in ds.Tables[0].Columns)
{
header = header + (char)34 + col.ColumnName +
(char)34 + ",";
}
header = header.Substring(0, header.Length - 1);

foreach (DataRow row in ds.Tables[0].Rows)
{
Object[] arr = row.ItemArray;
for (int i = 0; i < arr.Length - 1; i++)
{
if (arr[i].ToString().IndexOf(",") > 0)
{
record = record + (char)34 +
arr[i].ToString() + (char)34 + ",";
}
else
{
record = record + arr[i].ToString() + ",";
}
}


body = body + record.Substring(0, record.Length) +
Environment.NewLine;
record = "";

String strData = header + Environment.NewLine +
body;
byte[] data =
System.Text.ASCIIEncoding.ASCII.GetBytes(strData);


Response.Clear();
Response.AddHeader("Content-Type", "text/vnd.ms-
excel");
Response.AddHeader("Content-Disposition",
"attachment;filename=report.csv" );
Response.BinaryWrite(data);
}
}
catch (Exception bug)
{
string tmp;
tmp = bug.Message;
Response.Redirect("../PageDenied.aspx");
}
finally
{
Response.End();

}


}

Thanks in Advance,
Arnab

.



Relevant Pages

  • Re: System.AccessViolationException
    ... internal string theAP; ... DataColumn col = new DataColumn; ... private string _pwd; ... foreach ...
    (microsoft.public.dotnet.languages.csharp)
  • Access denied
    ... First it builds wsdl string: ... foreach ... CSharpCodeProvider cscp = new CSharpCodeProvider; ... CompilerParameters cp = new CompilerParameters; ...
    (microsoft.public.dotnet.languages.csharp)
  • Access denied
    ... My problem is that it doesn't work if Anonymous Access is turned off. ... First it builds wsdl string: ... foreach ... CompilerParameters cp = new CompilerParameters; ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Weird Error Msg
    ... foreach file $txtfile { ... set TestStr ... want to match a glob-style pattern, a regular expression, or a fixed string. ... lists, and the foreach expects it's second argument to be a list. ...
    (comp.lang.tcl)
  • Re: Weird Error Msg
    ... foreach file $txtfile { ... puts "Searching file $file Textdata ....." ... want to match a glob-style pattern, a regular expression, or a fixed string. ...
    (comp.lang.tcl)