|
Issues with Response.Write() -- Laresuco --
Hello, I'm having some problems with a web application I hope someone can help me. I'm exporting some data to excel, so I used a simple class to do this. If I test the application in my computer (localhost) I don't have any problems to get file, but when I publish the site and I try to download the file it just pop up the Open/Save/Cancel dialog, click the Open or Save option and that's all. The file never is opened or downloaded. Any ideas. The function I'm using: public void ExportToExcel(DataTable PoDataTable) { string LsResult; UnicodeEncoding LoCodificacion; System.IO.StringWriter LoStringWriter; System.Web.UI.HtmlTextWriter LoHtmlWriter; System.Web.UI.WebControls.GridView LoGridView; System.Web.HttpResponse PoResponse = System.Web.HttpContext.Current.Response; PoResponse.Clear(); PoResponse.AddHeader(HTTP_HEADER_CONTENT, String.Concat(HTTP_ATTACHMENT, MsFileName, ".xls")); PoResponse.ContentType = HTTP_CONTENT_TYPE_EXCEL; LoStringWriter = new System.IO.StringWriter(); LoHtmlWriter = new System.Web.UI.HtmlTextWriter(LoStringWriter); LoGridView = new System.Web.UI.WebControls.GridView(); LoGridView.ID = "gvwReporte"; LoGridView.EmptyDataText = "No se encontradon datos"; LoGridView.DataSource = PoDataTable; LoGridView.DataBind(); LoGridView.RenderControl(LoHtmlWriter); LsResult = LoStringWriter.ToString(); LoCodificacion = new UnicodeEncoding(); PoResponse.AddHeader(HTTP_CONTENT_LENGTH, LoCodificacion.GetByteCount(LsResult).ToString()); PoResponse.Charset = MsCharset; PoResponse.Write(LsResult); PoResponse.End(); } |