|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Can a generic Crystal report be dynamically instantied at runtime?public static void CreatePDF() { DataSet ds = TestDAL.GetCrystalDS(); TestRpt rpt = new TestRpt(); rpt.SetDataSource(ds); rpt.ExportToDisk(ExportFormatType.PortableDocFormat, "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.PortableDocFormat, ReportName + ".pdf"); } I don't understand what your TestRpt class is...? Does it inherit from
ReportDocument? Could you post some code? It inherits from the Crystal ReportClass.
Show quoteHide quote "Bruce Wood" <brucew***@canada.com> wrote in message news:1146156294.909479.200760@e56g2000cwe.googlegroups.com... >I don't understand what your TestRpt class is...? Does it inherit from > ReportDocument? Could you post some code? > 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); 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? Show quoteHide quote "Bruce Wood" <brucew***@canada.com> wrote in message news:1146158422.196885.75270@i40g2000cwc.googlegroups.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); > 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. :-) 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. Hi,
"Bruce Wood" <brucew***@canada.com> wrote in message Yes, CR create a class with the same name than the report. The report itself news:1146156294.909479.200760@e56g2000cwe.googlegroups.com... >I don't understand what your TestRpt class is...? Does it inherit from > ReportDocument? Could you post some code? is created as a embedded resource. -- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation 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. -- Show quoteHide quoteIgnacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation "Thirsty Traveler" <nfr@nospam.com> wrote in message news:%23BEBXYhaGHA.428@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.PortableDocFormat, "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.PortableDocFormat, ReportName + > ".pdf"); > } > > 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. I like that idea... much easier to add reports without making coding
changes. Show quoteHide quote "tdavisjr" <tdavi***@gmail.com> wrote in message news:1146161417.544648.230930@y43g2000cwc.googlegroups.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. >
Other interesting topics
C# Interview questions
csharp language idea CSharpCodeProvider: referencing other generated "InMemory" assembl ConfigurationSection and Class Library Reading text data to double crlf Problem reading an XML string without first writing to disk Help on Silent Download of a File from Server To client C# calling JAVA web service - results are null backgroundworker and generics Protect from SYN flood |
|||||||||||||||||||||||