Search code examples
c#pdfreporting-servicescorrupt

SSRS report corrupt when writing to file with WriteAllBytes C#


We have a process that has SQL Server Reporting Services create a pdf file via

ReportExecutionService.Render 

from data in the database. Then we save the byte array that Render returns to the database. Later I get the byte array and do a

File.WriteAllBytes

to write it to disk before attaching it to an email and sending it. The problem I'm running into is that after writing the file to disk, it is corrupt somehow. I'm not sure what to look at, can anyone help?

Thanks

EDIT:

I can write the file from SSRS to disk before saving the byte array to the database and I can view that fine.


Solution

  • If you work with the byte[] returned by render, then things are fine, but if once you write that to the DB and read it back, you have problems, correct?

    Why don't you compare the array written in to the DB with the one you retrieve to find the problem? Then start looking into your DB write and read routines, finally your DB storage.

    I've done similar things without problems, such as taking the results of a Reporting Services call into a bytestream and attaching that directly to an email, both using a memorystream and an on-disk file. So the basics of this are sound and should work.