水晶报表应用之登录失败及导出解决方案
ReportDocument rd = new ReportDocument();
private void setcry()
{
TableLogOnInfo t=new TableLogOnInfo();
rd.Load(Server.MapPath("CrystalReport1.rpt")); //Load the Crystal Report
t.ConnectionInfo.ServerName="localhost"; //log the connection info here
t.ConnectionInfo.DatabaseName="Northwind";
t.ConnectionInfo.UserID="xxx";
t.ConnectionInfo.Password="xxx";
rd.Database.Tables["Categories"].ApplyLogOnInfo(t);//Save the connection info
DiskFileDestinationOptions dd = new DiskFileDestinationOptions();
string pdfname= @"..\CrystalReport1.pdf";
dd.DiskFileName =pdfname; //Save as a PDF file
rd.ExportOptions.DestinationOptions = dd;
rd.ExportOptions.ExportDestinationType=ExportDestinationType.DiskFile;
rd.ExportOptions.ExportFormatType=ExportFormatType.PortableDocFormat; // set the PDF format
rd.Export();
rd.Close();
Response.ClearContent(); //And the write the PDF file to the page
Response.ClearHeaders();
Response.ContentType="application/pdf";
Response.WriteFile(pdfname);
Response.Flush();
Response.Close();
}