Re: Export to CSV problem



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

.



Relevant Pages

  • Re: Multiple blanks
    ... when going through a large input (I usually test such things by copy ... string tmp = userInput; ... Well the regex tends to be slower, though easier to read and maintain. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Multiple blanks
    ... I have a string that a user puts in but he may put multiple blanks in ... this will search and replace every occurance of multiple whitespaces to one space. ... string tmp = userInput; ... The problem with these string and stringbuilder options is that you'll need to make multiple passes if you also want to remove multiple tabs, ...
    (microsoft.public.dotnet.languages.csharp)
  • Export to CSV problem
    ... string header = string.Empty; ... string body = string.Empty; ... foreach ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Export to CSV problem
    ... string header = string.Empty; ... string body = string.Empty; ... foreach ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Split Function
    ... Dim SplitCatcher As Object ... public void SendWebMail(string From, string To, string Subject, string Body, ...
    (microsoft.public.dotnet.framework.aspnet)