locked
How to save pdf-converted .rpt by user defined filename? RRS feed

  • Question

  • User-595193528 posted

    Hi,

    I'm using crystal report and I try to convert .rpt file to pdf. When I save the converted pdf, filename becomes the pagename by default.

    How to give my own filename while saving the pdf converted crystal report?

    Tuesday, December 17, 2013 8:08 AM

All replies

  • User1740231301 posted
    ReportDocument rptDoc = new ReportDocument();
    rptDoc.Load(Server.MapPath("ETR0040.rpt"));
    
    
    // Fetch report parameters to retrieve report data.
    ...
    
    // Retrieve report data.
    DataSet dsResult = DBGateway.ExecuteCommand('command');
    rptDoc.SetDataSource(dsResult);
    
    // Report parameters - to be passed if there are any parameters which should be passed to report.
    rptDoc.SetParameterValue("CustomerCode", customerCode);
    
    DiskFileDestinationOptions diskOpts = new DiskFileDestinationOptions();
    string targetFileName = Request.PhysicalApplicationPath + "Reports\\TempReports\\" + (new Random()).Next() + ".pdf";
    
    rptDoc.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
    rptDoc.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
    
    diskOpts.DiskFileName = targetFileName;
    rptDoc.ExportOptions.DestinationOptions = diskOpts;
    
    // Export report ... Server-Side.
     rptDoc.Export();
    
    FileInfo file = new FileInfo(targetFileName);
    
    Response.ClearContent();
    Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
    Response.AddHeader("Content-Length", file.Length.ToString());
    Response.ContentType = "application/pdf";
    Response.TransmitFile(file.FullName);

    set your name in targetFileName

    Tuesday, December 17, 2013 8:43 AM