jestges
jestges

Reputation: 3740

Save pdf with default name in export pdf

Hi I've uploaded my data into pdf using below code something like

my page is : empdata.aspx

code is:

Fname = "1.pdf"
    crDiskFileDestinationOptions = New DiskFileDestinationOptions
    crDiskFileDestinationOptions.DiskFileName = Fname
    crExportOptions = crReportDocument.ExportOptions
    With crExportOptions
        .DestinationOptions = crDiskFileDestinationOptions
        .ExportDestinationType = ExportDestinationType.DiskFile
        .ExportFormatType = ExportFormatType.PortableDocFormat
    End With
    crReportDocument.Export()

    With Response
        .ClearContent()
        .ClearHeaders()
        .ContentType = "application/pdf name=1.pdf"
        .AddHeader("content-disposition", "inline; filename=1.pdf")
        .WriteFile(Fname)
        .Flush()
        .Close()
    End With

but When I try to save my file, by default it is showing with my page name (empdata). But I want to display 1.pdf as default.

Anything wrong in this?

Upvotes: 1

Views: 1020

Answers (1)

Emanuele Greco
Emanuele Greco

Reputation: 12721

I use this code:

try
    {
     reportDocument.ExportToHttpResponse( 
                 ExportFormatType.PortableDocFormat
                 ,Response, true, "1.pdf");
    }
catch (System.Threading.ThreadAbortException)
    {
        //System.Threading.ThreadAbortException is thrown  
        //because, Response.End is called internally in ExportToHttpResponse method:
    }

and it works.

Upvotes: 1

Related Questions