Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Push model with a manually populated Dataset? Export to PDF?

Connection Problems

Push model with a manually populated Dataset? Export to PDF?

by  aftertaf  Posted    (Edited  )
After pulling out my hair [hairpull] for days on end, i am finally getting round to using Crystal reports for .NET with satisfactory results...

the PDF export problem is sorted

Code:
public void DoPDF(System.Web.SessionState.HttpSessionState httpSess, System.Web.HttpRequest httpreq, System.Web.UI.Page httpPage, ref CrystalDecisions.CrystalReports.Engine.ReportDocument myReport) {
            HttpResponse httpresp = httpPage.Response;
            ExportOptions Export;
            DiskFileDestinationOptions tempFileOptions;
            string tempFilename;
        
            tempFilename = "c:\\TEMP\\" + httpSess.SessionID.ToString() + ".pdf";
            tempFileOptions = new DiskFileDestinationOptions();
            tempFileOptions.DiskFileName = tempFilename;
            Export = myReport.ExportOptions;
            Export.DestinationOptions = tempFileOptions;
            Export.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
            Export.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;

            myReport.Export();

            httpresp.ClearContent();
            httpresp.ClearHeaders();
            httpresp.ContentType = "application/pdf";
            httpresp.WriteFile(tempFilename);
            httpresp.Flush();
            httpresp.Close();

            System.IO.File.Delete(tempFilename);
        }

stick this code in a new class and call it...


Code:
reporting posteReport = new reporting();
posteReport.DoPDF(Session, Request, Page, ref myReport);

that way any page and any ReportDocument can be exported to PDF with very litte extra effort

don't forget to repopulate the data as well before calling the ExportPDF code...




and for the Push Model... up until now i've been using the Pull model with SQL Server 2000, but since i have Stored procedures with 15 parameters and seeing as CR.NET hates it when a report is linked to a Stored Procedure that has logic and if clauses, throwing all sorts of errors... i decided to go with the Push model.

Four steps to do:
__creation__
-define a dataset file (CR gets its field references here)
-build the report using dataset file as source
(dataset file can then be deleted.....)
___run time____
-fill a dataset object in the code (which creates a datatable within the dataset)
-associate the report to the dataset object

it all works well, until Boom!, run time gives you a nice Engine Exception : Query Error of some kind (don't have the exact term, using a french version)

the trick is, give the dataset a name...
and also give this same name to the datatable you create in step 3.

and the ABSOLUTE MUST for help (seeing as there is little to no doc around)
http://www.crystalreportsbook.com/
a free, complete book on CR for .NET
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top