本文介绍了显示来自 Reporting Services 的 PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示从我的 WinForms 应用程序中的 Reporting Services 生成的 PDF.

I would like to display a PDF generated from Reporting Services from my WinForms app.

我尝试了以下方法:

Uri uri = new Uri("http://myReportServer?MyReport&rs%3aCommand=Render&rs:Format=pdf");
System.Diagnostics.Process.Start(uri.ToString());

这会启动浏览器,然后浏览器会提示我打开或保存此文件.

Which launches a browser, which then in turn prompts me to open or save this file.

理想情况下,我只想在浏览器或 PDF 查看器中显示文件.问题是我必须同时打开浏览器和 PDF 查看器,这是用户不想要的.

Ideally I would like to display only the file, either in the browser or in a PDF viewer. Problem is I have to open both the browser and then PDF viewer, which the users doesn't want.

是否有一种简单的方法可以仅使用 URL 来执行此操作?

Is there a simple way to do this using just the URL?

我的另一种选择是编写一些看起来很简单的 C# 代码.这里有一些例子:

My other alternative is to just write some C# code which seems straight forward. There are some examples here:

http://geekswithblogs.net/bsherwin/archive/2007/04/29/112094.aspx

这里:

http://www.codeproject.com/KB/reporting-services/PDFUsingSQLRepServices.aspx

推荐答案

您可以将 PDF 下载到磁盘,然后使用 Process.Start 来显示它.

You can download PDF to disk and then use Process.Start to show it.

看看这个例子:

        Uri uriDownload = new Uri("http://myReportServer?MyReport&rs%3aCommand=Render&rs:Format=pdf");
        string strSavePath = @"C:	est	est123.pdf";

        System.Net.WebClient wcli = new System.Net.WebClient();
        wcli.DownloadFile(uriDownload, strSavePath);
        System.Diagnostics.Process.Start(strSavePath);

更新:

如果这在默认情况下不起作用,请尝试在 wcli.DownloadFile() 之前添加:

If that does not work by default, try to add this before wcli.DownloadFile():

        wcli.Credentials = new NetworkCredential("username", "password", "domain");
        wcli.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");

这篇关于显示来自 Reporting Services 的 PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 07:04
查看更多