cancel
Showing results for 
Search instead for 
Did you mean: 

Loading report in Crystal Report Viewer in another thread

Former Member
0 Kudos

I'm using a CrystalReportViewer (from vs2008) to show a report in a wpf application.

Because I want to get the total page count from the report, on loading the report I do a crystalReportViewer.ShowLastPage(), than a .GetCurrentPageNumber() and than a .ShowFirstPage().

With this method i'm not only getting the total number of pages, but also the report is loaded in 'cache' so browsing the report is faster.

But, as long as the .ShowLastPage() method is busy, my wpf application (or any other application i'm using the viewer in), is locked.

Is there a way to load the whole report on another thread? So my program will continue running while the report is loading...

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

you can export your report and show it in a browser Using the ExportToHttpResponse() Method

For e.g. -

ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType formatType, System.Web.HttpResponse response, bool asAttachment, string attachmentName)

ExportToHttpResponse(CrystalDecisions.Shared.ExportOptions options, System.Web.HttpResponse response, bool asAttachment, string attachmentName)

For exporting you can download sample code from [here|https://boc.sdn.sap.com/codesamples].

You can also take help from [Dev library|https://boc.sdn.sap.com/node/7770]

Hope this helps!!

Regards,

Amit

Former Member
0 Kudos

Sorry, but is this an answer to my question?

I'm asking if it's possible to 'load' the report in another thread for showing the report inside a WPF application, and you answer this question with how to export a report to a http response?

Am I missing something?

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Dennis,

Sorry I don't have an answer for you but I'm stuck with a similar problem. I'm trying to load several reports each displaying in it's own report viewer component in a tabcontrol. Just want to know if you found any more info regarding the issue?

At the moment, my application waits for each report to finish loading before the apllication becomes responsive again. (VS2008 + CR2008 SP1)

Thanx

Philip

former_member183750
Active Contributor
0 Kudos

This is a snippet of code where the report is exported via a thread. Now, since CR is based on Single Thread Apartment model, the report must remain within the thread. See if this snippet will help:


using System;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

namespace thread
{
	/// <summary>
	/// Summary description for clsThread.
	/// </summary>
    
//	
      
	public class clsThread
	{
		ReportDocument crRPT = new ReportDocument ();
		string strExportFileName;

		public clsThread(string strRPTName, string strExportName)
		{
			//
			// TODO: Add constructor logic here
			//
			// Load report return true if successfull false otherwise
			try 
			{
				strExportFileName = strExportName;
				crRPT.Load (strRPTName);

			}
			catch
			{
				throw;
			}
		}

		public void ExportToRPT()
		{
			//
			// TODO: Add constructor logic here
			//
			try 
			{
				crRPT.ExportToDisk (ExportFormatType.CrystalReport,strExportFileName);
				crRPT = null;
			}
			catch
			{
				throw;
			}
		}

		public void ExportToRTF()
		{
			//
			// TODO: Add constructor logic here
			//
			try 
			{
				
				crRPT.ExportToDisk (ExportFormatType.RichText,strExportFileName);
				crRPT = null;
			}
			catch
			{
				throw;
			}
		}

		public void ExportToPDF()
		{
			//
			// TODO: Add constructor logic here
			//
			try 
			{
				crRPT.ExportToDisk (ExportFormatType.PortableDocFormat,strExportFileName);
				crRPT = null;

			}
			catch
			{
				throw;
			}
		}

	}
}

Ludek