cancel
Showing results for 
Search instead for 
Did you mean: 

Add report from database into CrystalReportViewer in memory.

Former Member
0 Kudos

I have Crystal Reports saved in our database, and want to show the reports in the CrystalReportViewer on a windows form.

Is there a way to show the report in the viewer without saving the report first to the file system?

Now I have the following code:

            ...
            var fileByteArray = (byte[])_GetDataReplyMessage.DataSet.Tables[0].Rows[0]["RAPPORT"];

            var tempFileName = Path.GetTempFileName() + ".rpt";
            var saveOk = SaveFile(fileByteArray, tempFileName);
            this.crystalReportViewer.ReportSource = tempFileName;
            ...

      public static bool SaveFile(byte[] byteArray, string path, bool overwrite)
      {
         var saveFile = false;
         if (File.Exists(path) && !overwrite)
         {
            throw new IOException("File already exists");
         }

         // Write bytearray in parts to file system.
         // This will prevent al long lock of the file system resource.
         int part = 1024;
         int cursor = 0;
         using (var fileStream = new FileStream(path, FileMode.Create))
         {
            while (cursor < byteArray.Length)
            {
               byte[] bytesToWrite = byteArray.Skip(cursor).Take(part).ToArray();
               fileStream.Write(bytesToWrite, 0, bytesToWrite.Length);
               cursor += part;
            }
            fileStream.Close();
         }
         saveFile = true;
         return saveFile;
      }

This way the report needs to be on the clients filesystem.

The crystalReportViewer.ReportSource property is of the type 'object', and I am wondering if I can set this property with something else than a filename. I tried to set the ReportSource property with a memorystream, but this does not seem to work.

Accepted Solutions (1)

Accepted Solutions (1)

former_member183750
Active Contributor
0 Kudos

No you can not. The report object must exist physically.

Ludek

Answers (2)

Answers (2)

Former Member
0 Kudos

Crystal Report needs a physical file to work

former_member200290
Contributor
0 Kudos

Ludek's answer is absolutley correct as our engine will make a temp copy of the RPT file and work from it, you will need to have a physical copy of the report for this to work.

Trevor