BinaryWrite CorruptFile

Discussion in 'ASP .Net Web Services' started by Heath, Jun 3, 2005.

  1. Heath

    Heath Guest

    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???
     
    Heath, Jun 3, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DAC
    Replies:
    1
    Views:
    1,857
    Steve C. Orr, MCSD
    Jul 31, 2003
  2. Nik

    c#, binarywrite method.

    Nik, Oct 21, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    4,226
    Dmitriy Lapshin [C# / .NET MVP]
    Oct 21, 2003
  3. Vinay
    Replies:
    2
    Views:
    1,249
    Vinay
    Nov 7, 2003
  4. Gregory Silvano

    .NET Bug with BinaryWrite or just bad code?

    Gregory Silvano, Dec 22, 2003, in forum: ASP .Net
    Replies:
    5
    Views:
    690
    Gregory Silvano
    Dec 23, 2003
  5. =?Utf-8?B?QnJhZCBSb2JlcnRz?=

    RE: Response.BinaryWrite or something causes multiple posts

    =?Utf-8?B?QnJhZCBSb2JlcnRz?=, Aug 19, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    561
    =?Utf-8?B?RGFuIEM=?=
    Aug 19, 2004
Loading...

Share This Page