G
Guest
Hi all,
Im having difficulty serving synamically generated PDFs to clients via
asp.net. Im using crystal reports to generate them. In my page load I have
the following:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
try
{
ReportDocument rd = new ReportDocument();
rd.Load(file);
for (int i = 1; i < Request.QueryString.Count; ++i)
{
//setup report parameter
}
MemoryStream oStream = null; // using System.IO
oStream =(MemoryStream)rd.ExportToStream
(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
Response.Clear();
Response.ContentType = "application/pdf";
Response.Buffer= true;
Response.BinaryWrite(oStream.ToArray());
}
catch (Exception ex)
{
throw new ApplicationException(ex.Message, ex);
}
Response.End();
}
Although this works fine, Page_load gets called twice before the pdf is
served to the client. Any ideas why this is? For a time intesive reoprt its
pretty critical that its only run the once!
Some notes:
If the Response.BinaryWrite call is commented out, page_load is only called
once, however I get a blank page (as expected).
On the other hand, if Response.End is commented out, then the pdf is served
as a download ("do you wish to open or save etc") with the aspx page as the
default filename - saving this as a pdf results in the report. Again,
page_load is only called the once.
Keeping both calls in displays the pdf correctly, but only after the second
call to page_load. There is a screen reload between the two calls though.
Thanks in advance,
Shak
Im having difficulty serving synamically generated PDFs to clients via
asp.net. Im using crystal reports to generate them. In my page load I have
the following:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
try
{
ReportDocument rd = new ReportDocument();
rd.Load(file);
for (int i = 1; i < Request.QueryString.Count; ++i)
{
//setup report parameter
}
MemoryStream oStream = null; // using System.IO
oStream =(MemoryStream)rd.ExportToStream
(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
Response.Clear();
Response.ContentType = "application/pdf";
Response.Buffer= true;
Response.BinaryWrite(oStream.ToArray());
}
catch (Exception ex)
{
throw new ApplicationException(ex.Message, ex);
}
Response.End();
}
Although this works fine, Page_load gets called twice before the pdf is
served to the client. Any ideas why this is? For a time intesive reoprt its
pretty critical that its only run the once!
Some notes:
If the Response.BinaryWrite call is commented out, page_load is only called
once, however I get a blank page (as expected).
On the other hand, if Response.End is commented out, then the pdf is served
as a download ("do you wish to open or save etc") with the aspx page as the
default filename - saving this as a pdf results in the report. Again,
page_load is only called the once.
Keeping both calls in displays the pdf correctly, but only after the second
call to page_load. There is a screen reload between the two calls though.
Thanks in advance,
Shak