And it works for me.
CrystalDecisions.ReportAppServer.ReportDefModel.Section rasSection;
CrystalDecisions.ReportAppServer.Controllers.SubreportClientDocument MyNewSub;
rasSection = rptClientDoc.ReportDefController.ReportDefinition.ReportHeaderArea.Sections[0];
//When adding a new subreport (as opposed to importing), you need to leave the ReportURL property blank
MyNewSub = rptClientDoc.SubreportController.ImportSubreport("World Sales Report", "C:\\Reports\\impsub.rpt", rasSection);
MyNewSub.DatabaseController.LogonEx("ServerName", "Database", "sa", "PW");
To get the links from an existing report, add the subreport and then link it and then you can use this to see what links are set and do the same in the linking API.
foreach (String resultField in rptClientDoc.SubreportController.GetSubreportNames())
{
textBox1 = resultField.ToString();
btnReportObjects.Text += "Subreport Name: " + textBox1;
btnReportObjects.AppendText(":\n");
SubreportLinks SubLinks = rptClientDoc.SubreportController.GetSubreportLinks(resultField.ToString());
for (int I = 0; I < SubLinks.Count; I++)
{
SubreportLink subLink = SubLinks[I];
textBox1 = subLink.LinkedParameterName.ToString();
btnReportObjects.Text += "PM-Name: " + textBox1;
btnReportObjects.AppendText("\n");
textBox1 = subLink.MainReportFieldName.ToString();
btnReportObjects.Text += "Main Field: " + textBox1;
btnReportObjects.AppendText("\n");
textBox1 = subLink.SubreportFieldName.ToString();
btnReportObjects.Text += " Sub Field: " + textBox1;
btnReportObjects.AppendText(" 'End' \n");
}
btnReportObjects.AppendText("\n");
btnCount.Text = SubLinks.Count.ToString();
}
Don