Activator.CreateInstance
-
Hello. Am not sure about this, hope someone can provide a little help. I've got a folder with a variety of pre-defined Crystal Reports which will need to be instantiated depending on some user input. This folder is not part of the solution, it's just sitting on a server drive. So assuming the input is rptTest, I need to instantiate the report called rptTest. If the app can't find a match, it alerts the user. Is it Activator.CreateInstance I need to accomplish this or is it simply not possible? If it is, can anyone provide a code sample. I know I need an assemblyname and a typename for one but which would be the user input and what would the other be? Hope I'm being clear and that someone can help. Thanks in advance
-
Hello. Am not sure about this, hope someone can provide a little help. I've got a folder with a variety of pre-defined Crystal Reports which will need to be instantiated depending on some user input. This folder is not part of the solution, it's just sitting on a server drive. So assuming the input is rptTest, I need to instantiate the report called rptTest. If the app can't find a match, it alerts the user. Is it Activator.CreateInstance I need to accomplish this or is it simply not possible? If it is, can anyone provide a code sample. I know I need an assemblyname and a typename for one but which would be the user input and what would the other be? Hope I'm being clear and that someone can help. Thanks in advance
Activator.CreateInstance is used to create instances of C#/.Net types at runtime. This allows you to switch which class gets created based on runtime information (user input or information provided by virtual methods, for example).
abstract class A {}
class B : A {}
class C : A {}A CreateSomething(string classname){
return Activator.CreateInstance(Type.GetType(classname));
}A CreateSomethingOfTheSameType(A template){
return Activator.CreateInstance(template.GetType());
}I don't believe Crystal Reports are saved as .Net classes and thus this won't be the correct approach. I would imagine that Crystal allows you to load reports from file.
-
Hello. Am not sure about this, hope someone can provide a little help. I've got a folder with a variety of pre-defined Crystal Reports which will need to be instantiated depending on some user input. This folder is not part of the solution, it's just sitting on a server drive. So assuming the input is rptTest, I need to instantiate the report called rptTest. If the app can't find a match, it alerts the user. Is it Activator.CreateInstance I need to accomplish this or is it simply not possible? If it is, can anyone provide a code sample. I know I need an assemblyname and a typename for one but which would be the user input and what would the other be? Hope I'm being clear and that someone can help. Thanks in advance
Here's what I use:
System.IO.FileInfo Defile
...
CrystalDecisions.CrystalReports.Engine.ReportDocument crRpt =
new CrystalDecisions.CrystalReports.Engine.ReportDocument() ;
crRpt.Load ( Defile.FullName ) ; -
Here's what I use:
System.IO.FileInfo Defile
...
CrystalDecisions.CrystalReports.Engine.ReportDocument crRpt =
new CrystalDecisions.CrystalReports.Engine.ReportDocument() ;
crRpt.Load ( Defile.FullName ) ;Thanks for the answers guys, much appreciated. Just one more thing, is there a way I can instantiate a custom dataset on the fly as well. Similar to the crystal reports, I've another folder which contains XSDs to use as the datasources for the reports. Could they also be generated according to user input? Thanks again for your help so far.
-
Thanks for the answers guys, much appreciated. Just one more thing, is there a way I can instantiate a custom dataset on the fly as well. Similar to the crystal reports, I've another folder which contains XSDs to use as the datasources for the reports. Could they also be generated according to user input? Thanks again for your help so far.
-
You can construct a DataSet manually at runtime (adding tables, columns, rows etc), or you can use DataSet.ReadXml.