On the ASPX page, set connectionstring and parameters to input a report, and use crystalreportviewer to use exporttohttpresponse to output a PDF file for download.
Private void exportpdfreport ()
{
If (file. exists (mappath ("~ /Reports/dropshipinvoice. rpt ")))
{
ReportDocument rptdropshipinvoice = new reportdocument ();
// Obtain the report location and Load
Rptdropshipinvoice. Load (mappath ("~ /Reports/dropshipinvoice. rpt "));
Rptdropshipinvoice. reportoptions. enablesavedatawithreport = false;
// Initialize database connection information. Set the connection string
VaR connectionstring =
New sqlconnectionstringbuilder (dbutils. actualconnectionstring );
// Set the connection string for each report or subreport in the report.
Foreach (iconnectioninfo connection in rptdropshipinvoice. cececonnections)
{
If (connectionstring. integratedsecurity)
{
Connection. setconnection (connectionstring. datasource, connectionstring. initialcatalog,
Connectionstring. integratedsecurity );
}
Else
{
Connection. setconnection (connectionstring. datasource, connectionstring. initialcatalog,
Connectionstring. userid, connectionstring. Password );
}
}
// Input parameters to the report
Rptdropshipinvoice. setparametervalue ("begindate", calandarshipday. selecteddate );
Rptdropshipinvoice. setparametervalue ("enddate", calandarshipday. selecteddate. adddays (1 ));
Rptdropshipinvoice. setparametervalue ("customeruserid", currentloginuser. userid. tostring ());
Rptdropshipinvoice. setparametervalue ("mainsiteapplicationid", systemconfiguration. mainsiteapplicationid. tostring ());
// Export a report
Exportreport (rptdropshipinvoice, "dropshipinvoice" + calandarshipday. selecteddate. tostring ("yyyymmdd"), exportformattype. portabledocformat );
}
// Exportreport method. Export the data in the report template on the ASPX page and generate a PDF file.
Private void exportreport (corresponding parameter)
{
Httpcontext. Current. response. Buffer = false;
// Clear the response content and headers
Httpcontext. Current. response. clearcontent ();
Httpcontext. Current. response. clearheaders ();
Rptdropshipinvoice. exporttohttpresponse (formattype, httpcontext. Current. Response, true, strexportfilename );
Httpcontext. Current. response. Flush ();
Httpcontext. Current. response. End ();
}