Using system; using system. collections; using system. componentmodel; using system. configuration; using system. data; using system. drawing; using system. web; using system. web. sessionstate; using system. web. ui; using system. web. UI. webcontrols; using system. web. UI. htmlcontrols; // introduce two dllusing crystaldecisions. shared; using crystaldecisions. crystalreports. engine; using system. io; using ghy. funds. fundsclasslibrar Y; using system. Data. sqlclient; namespace webapptest {// <summary> /// abstract description of webform1. /// </Summary> public class webform2: system. web. UI. page {protected system. web. UI. webcontrols. dropdownlist dropdownlist1; protected crystaldecisions. web. crystalreportviewer crystalreportviewer1; protected system. web. UI. webcontrols. button btn_export2; reportdocument reportdoc = new reportdocument (); // load sqlconnection myconn = new sqlconnection (configurationsettings. appsettings ["connectstring"]); // Sqlconnection myconn1 = new sqlconnection (configurationsettings. appsettings ["connectstring"]); // reads the web. the database connection string in the config configuration file and connects to the specified database private void page_load (Object sender, system. eventargs e) {// put user code to initialize the page here // reportdatabind (); If (! Page. ispostback) {// bind reportdatabind () ;}# region web form designer generated code override protected void oninit (eventargs e) {// codegen: this call is required by the ASP. net web form designer. // initializecomponent (); base. oninit (E);} // <summary> // required method for designer support-do not modify // the contents of this method with the code editor. /// </Summary> private Void initializecomponent () {This. btn_export2.click + = new system. eventhandler (this. btn_export2_click); this. load + = new system. eventhandler (this. page_load) ;}# endregion // bind the data source private void reportdatabind () {string SQL = "select distinct, funds_rpt_hq.ingds, distinct, distinct, funds_rpt_hq.pay Oth, funds_rpt_hq.amt_end, begin, expire, funds_rpt_hq.fee_end from funds_rpt_hq where funds_rpt_hq.form_date = '2017-05-09 '"; myconn. open (); sqldataadapter mycomm = new sqldataadapter (SQL, myconn); // dataset dset1 = new dataset (); mycomm. fill (dset1, "funds_rpt_hq"); myconn. close (); string ls_rptpathname; ls_rptpathname = server. mappath (". ") +" \ funds_rpt_hq.rpt "; Reportdoc. load (ls_rptpathname); reportdoc. setdatasource (dset1); crystalreportviewer1.reportsource = reportdoc; crystalreportviewer1.databind () ;}// private void btn_export2_click (Object sender, system. eventargs e) {try {reportdatabind (); string exportpath; string fname; exportpath = request. physicalapplicationpath + "exported"; if (! Directory. exists (exportpath) {system. io. directory. createdirectory (request. physicalapplicationpath + "exported");} fname = "funds_rpt_hq"; crystaldecisions. shared. diskfiledestinationoptions opts = new crystaldecisions. shared. diskfiledestinationoptions (); // export as the disk file crystaldecisions. shared. exportoptions myexportoptions = reportdoc. exportoptions; myexportoptions. destinationoptions = opts; myexportop Tions. exportdestinationtype = crystaldecisions. shared. exportdestinationtype. diskfile; // export to reportdoc in pdf format. exportoptions. exportformattype = crystaldecisions. shared. exportformattype. portabledocformat; // Destination path fname = fname + ". PDF "; opts. diskfilename = exportpath + fname; // Export Operation reportdoc. export (); commoncode. export howwindow ("exported file successful! ");} Catch (exception ex) {commoncode. Export howwindow (" An error occurred while exporting the file! "+ Ex. Message. tostring (). substring (); Return ;}}}}