CrystalDecisions.Web.CrystalReportViewer CRtV1;
string strSql,strConnection;
SqlConnection objConnection=null;
SqlDataAdapter objAdapter=null;
DataSet objDataset=new DS1();
strConnection="server=killerwc;database=me;uid=sa;pwd=sophie.wang";
strSql="select * from V_Student_TrvNodeStudent";
objConnection=new SqlConnection(strConnection);
objAdapter=new SqlDataAdapter(strSql,objConnection);
objAdapter.Fill (objDataset,"V_Student_TrvNodeStudent");
objConnection.Close();
CR3 oRpt=new CR3();//报表类名字
oRpt.SetDataSource(objDataset);
ExportOptions crOpt;
DiskFileDestinationOptions crDFDO;
string Fname="c:\\inetpub\\wwwroot\\CrystalReport\\a.pdf";
ExcelFormatOptions excelFormatOpts = new ExcelFormatOptions();
excelFormatOpts.ExcelTabHasColumnHeadings =true;
crDFDO=new DiskFileDestinationOptions();
crDFDO.DiskFileName=Server.MapPath(@"a.pdf") ;
crOpt=oRpt.ExportOptions;
crOpt.DestinationOptions=crDFDO;
crOpt.ExportDestinationType=ExportDestinationType.DiskFile;
crOpt.ExportFormatType=ExportFormatType.PortableDocFormat ;
oRpt.Export();
Response.ClearContent();
Response.ClearHeaders();
Response.AppendHeader("Content-Disposition","inline;filename=" + Server.UrlEncode(Path.GetFileName(Fname)));
Response.ContentType = "application/pdf";
Response.WriteFile(Fname);
Response.Flush();
Response.Close();
System.IO.File.Delete(Fname);
string strSql,strConnection;
SqlConnection objConnection=null;
SqlDataAdapter objAdapter=null;
DataSet objDataset=new DS1();
strConnection="server=killerwc;database=me;uid=sa;pwd=sophie.wang";
strSql="select * from V_Student_TrvNodeStudent";
objConnection=new SqlConnection(strConnection);
objAdapter=new SqlDataAdapter(strSql,objConnection);
objAdapter.Fill (objDataset,"V_Student_TrvNodeStudent");
objConnection.Close();
CR3 oRpt=new CR3();//报表类名字
oRpt.SetDataSource(objDataset);
ExportOptions crOpt;
DiskFileDestinationOptions crDFDO;
string Fname="c:\\inetpub\\wwwroot\\CrystalReport\\a.pdf";
ExcelFormatOptions excelFormatOpts = new ExcelFormatOptions();
excelFormatOpts.ExcelTabHasColumnHeadings =true;
crDFDO=new DiskFileDestinationOptions();
crDFDO.DiskFileName=Server.MapPath(@"a.pdf") ;
crOpt=oRpt.ExportOptions;
crOpt.DestinationOptions=crDFDO;
crOpt.ExportDestinationType=ExportDestinationType.DiskFile;
crOpt.ExportFormatType=ExportFormatType.PortableDocFormat ;
oRpt.Export();
Response.ClearContent();
Response.ClearHeaders();
Response.AppendHeader("Content-Disposition","inline;filename=" + Server.UrlEncode(Path.GetFileName(Fname)));
Response.ContentType = "application/pdf";
Response.WriteFile(Fname);
Response.Flush();
Response.Close();
System.IO.File.Delete(Fname);
http://support.crystaldecisions.com/communityCS/TechnicalPapers/crnet_web_app_printing.pdf
oRpt.Export();
然后在必要的时候下载
Response.WriteFile(Fname);
然后删除
System.IO.File.Delete(Fname);
这里连起来写了