Re: Export to CSV problem
- From: "arnabit@xxxxxxxxx" <arnabit@xxxxxxxxx>
- Date: Thu, 19 Jul 2007 23:29:44 -0700
On Jul 19, 12:54 am, Sergey Poberezovskiy
<SergeyPoberezovs...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
use vnd.xls instead of vnd.ms-excel in content-disposition
"arna...@xxxxxxxxx" wrote:
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- Hide quoted text -
- Show quoted text -
My problem is solved i have used System.Web.Current.Response.Write()
instead of Response.BinaryWrite.It solves my problem
.
- References:
- Export to CSV problem
- From: arnabit@xxxxxxxxx
- RE: Export to CSV problem
- From: Sergey Poberezovskiy
- Export to CSV problem
- Prev by Date: Re: Problems storing upload file in session (ObjectDisposedException)
- Next by Date: Re: ViewState or QueryString
- Previous by thread: RE: Export to CSV problem
- Next by thread: GetObject error in ASP.NET
- Index(es):
Relevant Pages
|