Cannot redirect after http headers have been sent asp.net - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Cannot redirect after http headers have been sent asp.net

varun_789varun_789 Posts: 7Member
hi friends,

i have trying to develop an application in which i have to export a report to pdf file.

i use crystal reports for that.

i also have to stream that report to client machine and do not have to store that on server.

this happens on a button's click event which is as follows.



protected void Button1_Click(object sender, EventArgs e)
{
ReportDocument StReport = new ReportDocument();

string reportPath = Server.MapPath(@~Report.rpt);

StReport.Load(reportPath);

ExportOptions crExportOptions;

crExportOptions = StReport.ExportOptions;

crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;

MemoryStream ms = (MemoryStream)StReport.ExportToStream(ExportFormatType.PortableDocFormat);

ms.WriteTo(Response.OutputStream);

Response.Flush();

//Response.Write("window.open('Default2.aspx')");

Response.Redirect("Default2.aspx");

}



i get the error i mentioned in the subject of this post.

i even tried javascript code which is commented in the listing above but that also failed.

kindly help me in this matter and show me the way forward.

thanks in advance.

Sign In or Register to comment.