danielivanov2
asked on
Chrome is exporting aspx file instead of xls
I use the code attached to export data in xls. It works fine in any browser, except Chrome, where the file is exported as aspx instead xls. It is something wrong with my code or it's a browser setting that shoud be modified? Thanks
Response.Clear();
Response.AddHeader("content-disposition", "oferta");
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
StringWriter stringWrite = new System.IO.StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
if (gv.Rows.Count>0)
{
htmlWrite.Write("<b>Client selectat:</b>");
gv.RenderControl(htmlWrite);
htmlWrite.WriteBreak();
}
string html = stringWrite.ToString();
string pattern=@"(\p{Sc})?";
System.Text.RegularExpressions.Regex rgx=new System.Text.RegularExpressions.Regex(pattern);
html = rgx.Replace(html, "");
Response.Write(html);
HttpContext.Current.Response.End();
try
Response.AddHeader("Conten t-Disposit ion", "attachment; filename=oferta.xls");
Response.AddHeader("Conten
ASKER
not working either way (Encoding or adding .xls)
ASKER
the problem appears when I'm trying to export more than 1 gridview. At 1 gridview export, the output is in xls format
maybe you're calling Reponse.End() twice?
ASKER
nope
i have attached a sample for at least 2 gridviews
i have attached a sample for at least 2 gridviews
Response.Clear();
Response.AddHeader("content-disposition", "oferta.xls");
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
StringWriter stringWrite = new System.IO.StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
GridView gv = (GridView)Master.FindControl("SelectionGridView");
if (gv.Rows.Count>0)
{
htmlWrite.Write("<b>Client selectat:</b>");
gv.RenderControl(htmlWrite);
htmlWrite.WriteBreak();
}
FormViewCustomerDataMV.RenderControl(htmlWrite);
htmlWrite.WriteBreak();
if (GridViewStandardOffersVF.Rows.Count > 0)
{
htmlWrite.Write("<b>Oferta standard voce mobila:</b>");
GridViewStandardOffersVF.RenderControl(htmlWrite);
htmlWrite.WriteBreak();
}
if (GridViewStandardOffersVFSMS4All.Rows.Count > 0)
{
htmlWrite.Write("<b>Oferta standard SMS4All:</b>");
GridViewStandardOffersVFSMS4All.RenderControl(htmlWrite);
htmlWrite.WriteBreak();
}
if (GridViewStandardOffersCompet.Rows.Count > 0)
{
htmlWrite.Write("<b>Oferta competitie:</b>");
GridViewStandardOffersCompet.RenderControl(htmlWrite);
htmlWrite.WriteBreak();
}
if (GridViewCustomOffers.Rows.Count > 0)
{
htmlWrite.Write("<b>Oferta customizata voce mobila:</b>");
GridViewCustomOffers.RenderControl(htmlWrite);
htmlWrite.WriteBreak();
}
string html = stringWrite.ToString();
string pattern=@"(\p{Sc})?";
System.Text.RegularExpressions.Regex rgx=new System.Text.RegularExpressions.Regex(pattern);
html = rgx.Replace(html, "");
//StringReader reader = new StringReader(html);
//Write xls document
Response.Write(html);
//end current Response
HttpContext.Current.Response.End();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have found the solution in first link:
it was missing "attachment;filename=" from Response Header - thanks~
it was missing "attachment;filename=" from Response Header - thanks~
HttpContext.Current.Respon
HttpContext.Current.Respon