1203980 - How to change the location of the .XSD and .XML files at runtime in a .NET application

SAP Knowledge Base Article - Public

1203980 - How to change the location of the .XSD and .XML files at runtime in a .NET application

Symptom

  • A Crystal Report was created using the native XML driver pointing to an XML file and schema. When run through a .NET application, the .XML and .XSD files are in a new location.
  • A report is created against the following files:
    • C:\Temp\nativeXML.xml
    • C:\Temp\nativeXML.xsd
  • At runtime the required files are located at:
    • D:\Change XML Native\nativeXML.xml
    • D:\Change XML Native\nativeXML.xsd
  • How do you change the location of the files in .NET Code?

Resolution

  • The ServerName property from ConnectionInfo holds the path to the .XML file.
  • The DatabaseName property holds the path to the .XSD file.
  • The Location property holds the Tablename property.
  • Use the following code:

''CR Variables

Dim ReportFileName As String
Dim crReportDocument As New ReportDocument

''Database

Dim crDatabase As Database
Dim crTables As Tables
Dim crTable As Table
Dim crTableLogOnInfos As TableLogOnInfos
Dim crTableLogOnInfo As TableLogOnInfo
Dim crConnectionInfo As ConnectionInfo
Dim crTableNum As Integer
Dim i As Integer

Private Sub Set_Location_XML()

'Setup the connection information structure to be used to log onto the datasource for the report.


crConnectionInfo = New ConnectionInfo

'Get the table information from the report

 

crDatabase = crReportDocument.Database
crTables = crDatabase.Tables

'Loop through all tables in the report and apply the connection information for each table.


For Each crTable In crTables
   crTableLogOnInfo = crTable.LogOnInfo
   crTableLogOnInfo.ConnectionInfo = crConnectionInfo
With crConnectionInfo
    .ServerName = "D:\Change XML Native\nativeXML.xml"  'XML file
    .DatabaseName = "D:\Change XML Native\nativeXML.xsd"  'XSD file
End With

'Display the table name for confirmation


MessageBox.Show("Location " & crTable.Location)
crTableLogOnInfo = crTable.LogOnInfo
crTableLogOnInfo.ConnectionInfo = crConnectionInfo
crTable.ApplyLogOnInfo(crTableLogOnInfo)

Next

End Sub

Keywords

XML, XSD, native driver, .NET , 7334483 , KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , How To

Product

SAP Crystal Reports, developer version for Microsoft Visual Studio ; SAP Crystal Reports, version for Visual Studio .NET 2008