BinaryWrite CorruptFile

H

Heath

I am creating a crystal report on a web service and converting it to a pdf.
I then export the stream to a byte array and return from the web service.
When I call response.BinaryWrite Adobe says that the file cannot be found or
is corrupted. Here is the sample code :
From the ASMX:
System.IO.Stream dataStream;
byte[] pdfReport = new byte[1];

// Create an instance of your report clas
try
{
// Set the data source for the report
ExportRequestContext requestCtx = new ExportRequestContext();
d.ExportOptions.ExportFormatType =
ExportFormatType.PortableDocFormat;
d.ExportOptions.FormatOptions = new PdfRtfWordFormatOptions();
requestCtx.ExportInfo = d.ExportOptions;
dataStream = d.FormatEngine.ExportToStream(requestCtx);

// Convert the data stream with the pdf report into an array
pdfReport = new byte[dataStream.Length];
dataStream.Read(pdfReport,0,(int)dataStream.Length );
dataStream.Close();

return pdfReport;
}
catch(Exception ex)
{
// Wrap exception and rethrow
// throw new BaseApplicationException("Web Service Exception", ex);
throw new Exception("Failure");
}
finally
{
// Cleanup code
reportData = null;
dataStream = null;
pdfReport = null;
}

Here is the code from the ASPX:

WebReference.WebReports w = new MetNavWeb.WebReference.WebReports();
Byte[] b = w.HelloWorld();
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "inline; filename=Document.pdf");
Response.BinaryWrite(b);
Response.Flush();

Can someone please steer me in the right direction???
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top