473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Can a generic Crystal report be dynamically instantied at runtime?

The following code will instantiate a specific Crystal report (TestRpt.rpt):

public static void CreatePDF()
{
DataSet ds = TestDAL.GetCrystalDS();
TestRpt rpt = new TestRpt();
rpt.SetDataSource(ds);
rpt.ExportToDisk(ExportFormatType.PortableDocForma t, "TestRpt.pdf");
}

However, I would like to generalize this so the report name can be passed
in... something like this (although I realize this won't work, but you get
the idea):

public static void CreatePDF(string reportName)
{
DataSet ds = TestDAL.GetCrystalDS();
ReportName rpt = new ReportName(); <<< how would I do something like
this at runtime?
rpt.SetDataSource(ds);
rpt.ExportToDisk(ExportFormatType.PortableDocForma t, ReportName +
".pdf");
}
Apr 27 '06 #1
10 4917
I don't understand what your TestRpt class is...? Does it inherit from
ReportDocument? Could you post some code?

Apr 27 '06 #2
It inherits from the Crystal ReportClass.

"Bruce Wood" <br*******@canada.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
I don't understand what your TestRpt class is...? Does it inherit from
ReportDocument? Could you post some code?

Apr 27 '06 #3
Ahh. That's in the .cs file generated by Visual Studio when it creates
the rpt, right?

I've never used that class for anything. I consider it junk. I
instantiate my reports at runtime like this:

ReportDocument myReport = new ReportDocument();
myReport.Load("MyReport.rpt");
myReport.SetDataSource(myDataSet);

Apr 27 '06 #4
Hi,

"Bruce Wood" <br*******@canada.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
I don't understand what your TestRpt class is...? Does it inherit from
ReportDocument? Could you post some code?


Yes, CR create a class with the same name than the report. The report itself
is created as a embedded resource.
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Apr 27 '06 #5
Hi,

You can use reflection to create an instance of the report you want to use.
see CreateInstance method for a couple of possible variants.
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Thirsty Traveler" <nf*@nospam.com> wrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
The following code will instantiate a specific Crystal report
(TestRpt.rpt):

public static void CreatePDF()
{
DataSet ds = TestDAL.GetCrystalDS();
TestRpt rpt = new TestRpt();
rpt.SetDataSource(ds);
rpt.ExportToDisk(ExportFormatType.PortableDocForma t, "TestRpt.pdf");
}

However, I would like to generalize this so the report name can be passed
in... something like this (although I realize this won't work, but you get
the idea):

public static void CreatePDF(string reportName)
{
DataSet ds = TestDAL.GetCrystalDS();
ReportName rpt = new ReportName(); <<< how would I do something like
this at runtime?
rpt.SetDataSource(ds);
rpt.ExportToDisk(ExportFormatType.PortableDocForma t, ReportName +
".pdf");
}

Apr 27 '06 #6
I would choose the option of loading the reports via the filesystem,
like someone suggested, instead of that class VS will create for you.
If you need to make changes to that report, all you have to do is
replace that report with the new one. On the other hand, if you are
loading it via the class name the VS.NET generates for you. You will
have to recompile your project for the changes to take place.

Apr 27 '06 #7
I like that idea... much easier to add reports without making coding
changes.

"tdavisjr" <td******@gmail.com> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.com...
I would choose the option of loading the reports via the filesystem,
like someone suggested, instead of that class VS will create for you.
If you need to make changes to that report, all you have to do is
replace that report with the new one. On the other hand, if you are
loading it via the class name the VS.NET generates for you. You will
have to recompile your project for the changes to take place.

Apr 27 '06 #8
Awesome... I implemented this suggestion and it is working and cool.

Now... let's kick it up a notch. I would like to build a stateless web farm
that imports the ReportDocument from a central source, i.e. Sql Server, so
that I don't have to deploy the report to every server or establish a
connection to a central file server.

Can anyone think of a way to do this?

"Bruce Wood" <br*******@canada.com> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com...
Ahh. That's in the .cs file generated by Visual Studio when it creates
the rpt, right?

I've never used that class for anything. I consider it junk. I
instantiate my reports at runtime like this:

ReportDocument myReport = new ReportDocument();
myReport.Load("MyReport.rpt");
myReport.SetDataSource(myDataSet);

Apr 28 '06 #9
I would just put it on a share drive and load it using a UNC path.
That's what we do here. Of course that requires, as you said, a
"connection to a central file server".

But then I can be a bit of a Luddite at times. :-)

Apr 28 '06 #10
I just double-checked. ReportDocument.Load() does not take a stream
argument, so you can't load the report from anywhere but a file.

So deploying it on a shared drive seems pretty much your only option.

Apr 28 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Joe | last post by:
Hi friends, I need dynamically generate the crystal line graph from the c# application. i used stored procedure.but i don't know how to connect the C#, stored procedure and crystal report. 1....
0
by: sandeep | last post by:
Mine requirement is to Put images on report(version which come with VS.NET) dynamically. For example if manager is looking a report then Image1.bmp should come and if normal Employee is looking for...
0
by: techsatish | last post by:
hi all, I have designed a chart using Crystal report 9.0 which comes along with Visual Studio.NET V1.1 2003.I have set the background color for my chart using the ChartExpert option...My color...
1
by: Eric | last post by:
Hi, Can somebody tell me a way to change the value of a textobject in a report at runtime. By the way if anyone know a way to know how many page my report are going to had in code it will be...
0
by: PAPutzback | last post by:
Is it possible to have a form where a user could select option for which fields they want to group a report. I'd like to have a default detail band and allow the user to group on up to two fields...
0
by: Badis | last post by:
Hi, I have posted this question in ASPNET forum and now I'm posting here because I need the answer urgently Pleaaaaase. How to generate a Crystal report dynamically the way that I can define the...
0
by: Badis | last post by:
Hi, How to generate a Crystal report dynamically the way that I can define the name of my report in run time. without having to go to Solution...|Add Item....|Cryustal Report ....etc Thanks
0
by: mailtogops | last post by:
Hi All, I am new to crystal report and done a small report for a project. I have a problem now. I am using Crystal Report 9.0 which comes with Visual Studio 2003 at my development...
0
by: itsbhabesh | last post by:
I have grid view having data in runtime.i want to create a crystal report dynamically to contain the exact data of gridview including the format it has been displayed in gridview. i want this for...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.