在export pdf中保存带有默认名称的pdf

时间:2012-02-24 08:02:37

标签: pdf crystal-reports export-to-pdf

您好我使用下面的代码

将我的数据上传到pdf中

我的页面是:empdata.aspx

代码是:

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

但是当我尝试保存文件时,默认情况下会显示我的页面名称(empdata)。但是我希望默认显示1.pdf。

这有什么不对吗?

1 个答案:

答案 0 :(得分:1)

我使用此代码:

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:
    }

它有效。