C#的Response.Write PDF与Android浏览器工作 [英] C# Response.Write pdf not working with Android Browser

查看:214
本文介绍了C#的Response.Write PDF与Android浏览器工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前具有用PDF导出了Android环境的巨大问题。我使用的是报表查看器控件呈现到字节数组的报告。下一个我使用response.binarywrite方法输出字节流到浏览器。这在每一个浏览器以及iPhone和iPad。但是,它不会在Android上运行。

在PDF说,它已损坏。当我在记事本中打开PDF我看到它是出口我的整个页面的HTML,而不是通过报表查看器生成的字节数组。

在code:

 警告[]警告;
    字符串[] streamids;
    串mime类型;
    字符串编码;
    串延伸;
    字符串文件名=附件;文件名= Data.pdf;    字节[]字节= ReportViewer1.ServerReport.Render(
       PDF,空,出mime类型,出的编码,
        延伸出来,
       出streamids,出警告);    将Response.Buffer =真;
    Response.Clear();
    Response.ContentType =应用程序/ PDF
    Response.AddHeader(内容处置,文件名);
    Response.BinaryWrite(字节);
    Response.Flush();
    到Response.End();


解决方案

如果还有的任何的HTML这个code之前,那么就会被发送到浏览器,因为的 Response.Clear() 仅清除缓冲的HTML输出和的 将Response.Buffer 只有在没有HTML已输出工作。

尝试要么$ P $的code之前pventing任何输出(以某种方式)或移动此code到自己的文件。然后,甩掉输出缓冲code的。

PS:这可能或可能不工作;我还没有机会测试它。也有很多的问题,与Android的内容处置,所以你可能要设置的MIME类型GalacticCowboy建议。

I am currently having huge issues with the android environment with a pdf export. i am using a report viewer control to render a report in to an array of bytes. Next i am using response.binarywrite method to output the byte stream to the browser. This works in every browser as well as iphone and ipad. However, it will not work on android.

The Pdf says that it is corrupted. When i open the pdf in notepad i see that it is exporting my entire page html instead of the byte array generated by the report viewer.

the code:

    Warning[] warnings;
    string[] streamids;
    string mimeType;
    string encoding;
    string extension;
    string filename = "attachment; filename=Data.pdf";

    byte[] bytes = ReportViewer1.ServerReport.Render(
       "PDF", null, out mimeType, out encoding,
        out extension,
       out streamids, out warnings);

    Response.Buffer = true;
    Response.Clear();
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", filename);
    Response.BinaryWrite(bytes);
    Response.Flush();
    Response.End();

解决方案

If there's any HTML before this code, then that will get sent to the browser because Response.Clear() only clears buffered HTML output, and Response.Buffer only works if no HTML has been outputted.

Try either preventing any output before the code (somehow) or moving this code to its own file. Then get rid of the output buffering code.

PS: This may or may not work; I haven't had a chance to test it. Also there's a lot of issues with Android's content-disposition, so you may want to set the MIME type as GalacticCowboy suggests.

这篇关于C#的Response.Write PDF与Android浏览器工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆