【问题标题】:c# on button click open pdf in new tab insted of downloadingc#在按钮上单击在新选项卡中打开pdf而不是下载
【发布时间】:2014-08-25 11:20:09
【问题描述】:

我有一个 .aspx 页面,它有一个单击按钮,打开一个 radwindow。radwindow 有一个新页面,内容包括一个按钮 onclick,其中创建和下载 pdf。我希望 pdf 打开一个新的选项卡或窗口,所以我将我的代码更改附件更改为内联

Hashtable deviceInfo = new Hashtable();
    deviceInfo.Add("FontEmbedding", "Subset");
    deviceInfo.Add("DocumentTitle", String.Format("TrackitManager - {0}", reportToExport.DocumentName));
    deviceInfo.Add("DocumentAuthor", "Trackit Systems Pty Ltd");

    ReportProcessor reportProcessor = new ReportProcessor();
    RenderingResult result = reportProcessor.RenderReport("PDF", reportToExport, deviceInfo);

    if (String.IsNullOrEmpty(filename))
        filename = result.DocumentName;



    context.Response.Clear();
    context.Response.ContentType = result.MimeType;
    context.Response.Cache.SetCacheability(HttpCacheability.Private);
    context.Response.Expires = -1;
    context.Response.Buffer = true;
    //context.Response.TransmitFile("~/Handlers/EnrollmentPDF.ashx");

    context.Response.AppendHeader("Content-Disposition", string.Format("attachment; filename=\"{0}.pdf\"", filename));

    context.Response.BinaryWrite(result.DocumentBytes);

    context.Response.End();

但这是在 radwindow 本身内打开 pdf。我希望它在新窗口中打开,但在 radwindow 之外。

【问题讨论】:

标签: pdf radwindow


【解决方案1】:

您必须提供正确的标题和 mimeType 来告诉浏览器下载文件 为此,您只需添加此行即可替换:

context.Response.ContentType = result.MimeType;

通过这一行:

Response.ContentType = "application/octectstream";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-11
    • 1970-01-01
    • 1970-01-01
    • 2022-07-30
    • 2019-09-20
    • 1970-01-01
    相关资源
    最近更新 更多