Skip to Content
0

How do I create a new report in C # programming?

Mar 23, 2017 at 09:30 AM

130

avatar image
Former Member

Hi everybody,

I want to create a new empty report with a database connection to XML files in C # programming.

Regards.

Matthieu.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

5 Answers

Best Answer
Don Williams
Mar 23, 2017 at 02:14 PM
0

Hi Matthieu,

You can find RAS samples here that can create reports from nothing:

https://wiki.scn.sap.com/wiki/display/BOBJ/Crystal+Reports+for+.NET+SDK+Samples

Requires the CR for VS .NET SDK from here:

https://wiki.scn.sap.com/wiki/display/BOBJ/Crystal+Reports%2C+Developer+for+Visual+Studio+Downloads

Don

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Mar 23, 2017 at 04:59 PM
0

Hi Dan,

Thanks, I find examples to modify ConnectionInfos tables, but I want to create a new file without table and I want to add tables in C # programming.

In another application I used this Java code and I want translate this in C# :

ReportClientDocument varReportHndl = new ReportClientDocument();
varReportHndl.setReportAppServer(ReportClientDocument.inprocConnectionString);
PropertyBag propertyBag;
IConnectionInfo cInfo;
varReportHndl.newDocument();
for (Map.Entry<String, String> entry : filePaths.entrySet()) {
	String path = entry.getValue();
	String tableName = entry.getKey();
	propertyBag = new PropertyBag();
	propertyBag.put(ATT_LOCAL_FILE, path);
	propertyBag.put("Local Schema File", xsdFile);
	propertyBag.put("Convert Multivalue to Table", Boolean.FALSE);
	propertyBag.put("Database DLL", "crdb_xml.dll");
	String cnxStr = path + ' ' + xsdFile;
	propertyBag.put(ATT_SERVER_NAME, cnxStr);
	propertyBag.put(ATT_PRE_QE_SERVER_NAME, cnxStr);
  
	cInfo = new ConnectionInfo();
	cInfo.setAttributes(propertyBag);
	Table table = new Table();
	table.setConnectionInfo(cInfo);
	table.setName(tableName);
	table.setAlias(tableName);
	varReportHndl.getDatabaseController().addTable(table, null);
}
varReportHndl.saveAs(rptFile.getName(), rptFile.getParent(), ReportSaveAsOptions._overwriteExisting);
Share
10 |10000 characters needed characters left characters exceeded
Don Williams
Mar 24, 2017 at 03:43 PM
0

Most of the API's are the same. Try a translator to convert Java to C#:

http://codecall.net/2014/03/27/best-tools-to-convert-java-to-c-source-code/

Don

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member May 09, 2017 at 03:36 PM
0

Thanks Don,

but I want a real sample who create a new RPT file with only database connection to XML files. In the past, I have already make this in Java. But now, I want write this in C#.

Can you help me please ?

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Aug 23, 2017 at 10:23 AM
0

Hi,

I have a new report, but when I want to add a new table connected to an XML file, I have a "System.Runtime.InteropServices.COMException: Failed to load database information" error.

I don't understand that mistake.

My XML file :

<?xml version="1.0" encoding="iso-8859-15"?>
<DATA_DIAPASON>
  <LIGNE>
    <data1>TEST IMPRESSION</data1>
    <data2>1234567890</data2>
    <data3_cn>26/07/2017</data3_cn>
    <data4_cn>0123456789</data4_cn>
    <imgLig>C:\\Editions\\Modeles\\img1.jpg</imgLig>
  </LIGNE>
  <LIGNE>
...

  </LIGNE>
</DATA_DIAPASON>

My XSD file :

<?xml version="1.0" encoding="ISO-8859-15"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="DATA_DIAPASON">
    <xs:complexType>
      <xs:choice maxOccurs="unbounded">
        <xs:element name="LIGNE">
          <xs:complexType>
            <xs:all>
              <xs:element name="data1">
                <xs:simpleType>
                  <xs:restriction base="xs:string">
                    <xs:length value="100"></xs:length>
                  </xs:restriction>
                </xs:simpleType>
              </xs:element>
              <xs:element name="data2">
                <xs:simpleType>
                  <xs:restriction base="xs:string">
                    <xs:length value="100"></xs:length>
                  </xs:restriction>
                </xs:simpleType>
              </xs:element>
              <xs:element name="data3_cn">
                <xs:simpleType>
                  <xs:restriction base="xs:string">
                    <xs:length value="100"></xs:length>
                  </xs:restriction>
                </xs:simpleType>
              </xs:element>
              <xs:element name="data4_cn">
                <xs:simpleType>
                  <xs:restriction base="xs:string">
                    <xs:length value="100"></xs:length>
                  </xs:restriction>
                </xs:simpleType>
              </xs:element>
              <xs:element name="imgLig">
                <xs:simpleType>
                  <xs:restriction base="xs:string">
                    <xs:length value="100"></xs:length>
                  </xs:restriction>
                </xs:simpleType>
              </xs:element>
            </xs:all>
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>

My code :

public void AddTableReport()
        {
            // Load new report
            var myReport = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
            myReport.Load(@"C:/tmp/ISIAf20701692/ISImpCrystal.rpt");

            var reportClientDoc = myReport.ReportClientDocument;
            string schemaURL = @"C:/tmp/ISIAf20701692/" + "ISImpCrystal.xsd";
            string xmlURL = @"C:/tmp/ISIAf20701692/" + "ISImpCrystal_LIGNE.xml";
          
            // Set properties
            PropertyBag logonProperties = new PropertyBag();
            logonProperties["Local Schema File"] = schemaURL;
            logonProperties["Local XML File"] = xmlURL;
            
            PropertyBag connAttributes = new PropertyBag();
            connAttributes["Database DLL"] = "crdb_xml.dll";
            connAttributes["QE_DatabaseName"] = "";
            connAttributes["QE_DatabaseType"] = "XML";
            connAttributes["QE_LogonProperties"] = logonProperties;
            connAttributes["QE_ServerDescription"] = xmlURL + " " + schemaURL;
            connAttributes["Server"] = xmlURL + " " + schemaURL;
            connAttributes["Server Name"] = xmlURL + " " + schemaURL;
            connAttributes["PreQEServerName"] = xmlURL + " " + schemaURL;
            connAttributes["QE_SQLDB"] = false;
            connAttributes["SSO Enabled"] = false;

            ConnectionInfo connInfo = new ConnectionInfo();
            connInfo.UserName = "";
            connInfo.Password = "";
            connInfo.Kind = CrConnectionInfoKindEnum.crConnectionInfoKindCRQE;
            connInfo.Attributes = connAttributes;

            // Create new table
            CrystalDecisions.ReportAppServer.DataDefModel.Table tbl = new CrystalDecisions.ReportAppServer.DataDefModel.Table();
            tbl.Name = "DATA_DIAPASON/LIGNE";
            tbl.Alias = "DATA_DIAPASON/LIGNE";            
            tbl.ConnectionInfo = connInfo;


            // Add new table : this line shot down
            reportClientDoc.DatabaseController.AddTable(tbl, null);

            // Save report
            string fichier = "ISImpCrystalNET2";
            string chemin = "C:/tmp/ISIAf20701692/";
            System.IO.File.Delete(chemin + fichier);
            reportClientDoc.SaveAs(fichier, chemin);
        }

Thanks for your help in advance.

Matthieu.

Share
10 |10000 characters needed characters left characters exceeded