Can somebody please shed some light on this as to what im doing wrong?
None of my posts ever get answered :-(
Thanks :-)
Fev
FeveZ,
You can easily stream your report as a PDF straight to the browser, too.
Looks much
more professional than the ugly crystal control on the screen. Here's how to
do what you want (in a nutshell):
1) In your webservice, set your report to get its data from a dataset
2) Have your data layer retrieve the report data in the form of a DataSet
3) Set the reports DataSource (.SetDataSource) to the DataSet in 3)
4) Export the report to a stream (ExportToStream), and convert it to a array
of bytes
5) Return the byte array to the calling web page, which can
Response.BinaryWrite it to the client browser
6) Wipe hands on pants and repeat!
Here's sample code:
yada yada yada: it's always nice to see the USINGS!!
using System;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using Microsoft.ApplicationBlocks.ExceptionManagement;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
[WebMethod]
public byte[] GetDataForDTReport(int fiscalYearId,int programId,int
languageId)
{
// Declaration section
ReportDs report = new ReportDs(); //our data service
DataSet reportData = new DataSet();
System.IO.Stream dataStream;
byte[] pdfReport = new byte[1];
ExportRequestContext requestCtx = new ExportRequestContext();
// Create an instance of your report class
DTReport repDoc = new DTReport();
bool dataReturned = true;
try
{
// Validation section
// Call the data services for the report
reportData =
report.GetDataForDTReport(fiscalYearId,programId,languageId);
//If tables are returned
if(reportData.Tables.Count > 0)
{
//If at least one table has no rows
foreach(DataTable table in reportData.Tables)
{
if(table.Rows.Count == 0)
{
dataReturned = false;
break;
}
}
if(dataReturned)
{
// Set the data source for the report
repDoc.SetDataSource(reportData);
repDoc.ExportOptions.ExportFormatType =
ExportFormatType.PortableDocFormat;
repDoc.ExportOptions.FormatOptions = new PdfRtfWordFormatOptions();
requestCtx.ExportInfo = repDoc.ExportOptions;
dataStream = repDoc.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);
}
finally
{
// Cleanup code
reportData = null;
dataStream = null;
pdfReport = null;
}
}

Signature
Tim Gallivan
I know I'm a great teacher because when I give a lesson, the person never
comes back.
> I've been stuck on a problem now for ages and i'm about ready to pack my
> project in because of it lol.
[quoted text clipped - 25 lines]
>
> FeveZ
FeveZ - 17 Aug 2004 12:13 GMT
Sweet thanks... Cant test it right now because im away from my dev kit :-D
I'll let you know how it goes :D
Thanks again :-)
Fev