EDN Admin
Well-known member
Hi Guys,
I have an ASP app that Renders a PDF and then exports to client machine.
Now I am not sure if its the code or cross browser issue, but the only browser it works perfectly is Firefox...
Here is my Code:
<pre class="prettyprint using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;
namespace TNTWEB
{
public partial class ReportExport : System.Web.UI.Page
{
public string Parm;
public string Key;
public string TypeKey;
public string KeyVal;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.User.Identity.IsAuthenticated)
{
Response.Redirect(System.Web.Security.FormsAuthentication.LoginUrl);
}
Key = Request.QueryString["Type"];
Parm = Request.QueryString["Parm"];
if (Key == "1")
{
int Parm1 = Convert.ToInt32(Parm);
using (LocalReport lr = new LocalReport())
{
lr.ReportPath = HttpContext.Current.Server.MapPath("~/Local Reports/GRN.rdlc");
App_Data.uecdeczaDataSetTableAdapters.spGRNDataTableAdapter ta1 = new App_Data.uecdeczaDataSetTableAdapters.spGRNDataTableAdapter();
ReportDataSource ds1 = new ReportDataSource("DS", (DataTable)ta1.GetData(Parm1));
lr.DataSources.Add(ds1);
Microsoft.Reporting.WebForms.Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string filenameExtension;
byte[] bytes;
bytes = lr.Render("PDF", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);
using (MemoryStream s = new MemoryStream(bytes))
{
s.Seek(0, SeekOrigin.Begin);
Response.ContentType = "application/pdf";
Response.AppendHeader("content-disposition", "render; filename=GRN" + Parm1 + " " + System.DateTime.Now.ToShortDateString() + ".pdf");
Response.BinaryWrite(bytes);
Response.Flush();
Response.Close();
}
}
}
Response.Close();
}
}
}[/code]
If Anyone has any advice to do this in a better way, please let me know.....
For more info on this: http://forums.asp.net/p/1815397/5029642.aspx/1?Local+Report+Render+to+PDF+not+working+in+all+browsers+Inconsistant" target="_blank
MyASPQuestion
http://forums.asp.net/p/1815397/5029642.aspx/1?Local+Report+Render+to+PDF+not+working+in+all+browsers+Inconsistant A ny Advice will be greatly Appreciated
Thanks And Regards
Jacques <hr class="sig "Be polite, be professional, but have a plan to kill everybody you meet." Maj. Gen. James Mattis
View the full article
I have an ASP app that Renders a PDF and then exports to client machine.
Now I am not sure if its the code or cross browser issue, but the only browser it works perfectly is Firefox...
Here is my Code:
<pre class="prettyprint using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;
namespace TNTWEB
{
public partial class ReportExport : System.Web.UI.Page
{
public string Parm;
public string Key;
public string TypeKey;
public string KeyVal;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.User.Identity.IsAuthenticated)
{
Response.Redirect(System.Web.Security.FormsAuthentication.LoginUrl);
}
Key = Request.QueryString["Type"];
Parm = Request.QueryString["Parm"];
if (Key == "1")
{
int Parm1 = Convert.ToInt32(Parm);
using (LocalReport lr = new LocalReport())
{
lr.ReportPath = HttpContext.Current.Server.MapPath("~/Local Reports/GRN.rdlc");
App_Data.uecdeczaDataSetTableAdapters.spGRNDataTableAdapter ta1 = new App_Data.uecdeczaDataSetTableAdapters.spGRNDataTableAdapter();
ReportDataSource ds1 = new ReportDataSource("DS", (DataTable)ta1.GetData(Parm1));
lr.DataSources.Add(ds1);
Microsoft.Reporting.WebForms.Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string filenameExtension;
byte[] bytes;
bytes = lr.Render("PDF", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);
using (MemoryStream s = new MemoryStream(bytes))
{
s.Seek(0, SeekOrigin.Begin);
Response.ContentType = "application/pdf";
Response.AppendHeader("content-disposition", "render; filename=GRN" + Parm1 + " " + System.DateTime.Now.ToShortDateString() + ".pdf");
Response.BinaryWrite(bytes);
Response.Flush();
Response.Close();
}
}
}
Response.Close();
}
}
}[/code]
If Anyone has any advice to do this in a better way, please let me know.....
For more info on this: http://forums.asp.net/p/1815397/5029642.aspx/1?Local+Report+Render+to+PDF+not+working+in+all+browsers+Inconsistant" target="_blank
MyASPQuestion
http://forums.asp.net/p/1815397/5029642.aspx/1?Local+Report+Render+to+PDF+not+working+in+all+browsers+Inconsistant A ny Advice will be greatly Appreciated
Thanks And Regards
Jacques <hr class="sig "Be polite, be professional, but have a plan to kill everybody you meet." Maj. Gen. James Mattis
View the full article