on 09-23-2008 4:21 PM
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.
No you can not. The report object must exist physically.
Ludek
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Crystal Report needs a physical file to work
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
92 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.