I export a crystal report to the solution folder at the moment. i want to export the reports to a folder called REPORTS on the server.
I use the following code to export the reports:
rptBuildByDate crReportDocument = new rptBuildByDate();
crReportDocument.SetDataSource(this.dstBuildPDF2);
string ExportPath;
ExportPath = Request.PhysicalApplicationPath;
crDiskFileDestinationOptions = new DiskFileDestinationOptions();
crExportOptions = crReportDocument.ExportOptions;
Session["filename"] = Session.SessionID.ToString() + ".pdf";
crDiskFileDestinationOptions.DiskFileName = ExportPath + Session["filename"].ToString();
crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
crReportDocument.Export();
Response.Redirect("Webform2.aspx");
//redirected to webform2 so that the browser back button
//will bring you back to the webform that the report
//is run from
webform2.aspx:
public class WebForm2 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
string fName;
fName = Session["filename"].ToString();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.WriteFile(fName);
Response.Flush();
Response.Close();
}
I use the following code to export the reports:
rptBuildByDate crReportDocument = new rptBuildByDate();
crReportDocument.SetDataSource(this.dstBuildPDF2);
string ExportPath;
ExportPath = Request.PhysicalApplicationPath;
crDiskFileDestinationOptions = new DiskFileDestinationOptions();
crExportOptions = crReportDocument.ExportOptions;
Session["filename"] = Session.SessionID.ToString() + ".pdf";
crDiskFileDestinationOptions.DiskFileName = ExportPath + Session["filename"].ToString();
crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
crReportDocument.Export();
Response.Redirect("Webform2.aspx");
//redirected to webform2 so that the browser back button
//will bring you back to the webform that the report
//is run from
webform2.aspx:
public class WebForm2 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
string fName;
fName = Session["filename"].ToString();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.WriteFile(fName);
Response.Flush();
Response.Close();
}