显示 Reporting Services 中的 PDF

发布于 2024-10-29 06:07:42 字数 812 浏览 0 评论 0原文

我想在我的 WinForms 应用程序中显示由 Reporting Services 生成的 PDF。

我尝试了以下操作:

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

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

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

有没有一种简单的方法可以仅使用 URL 来完成此操作?

我的另一个选择是只编写一些看起来很简单的 C# 代码。这里有一些示例:

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

和此处:

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

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

I tried the following:

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.

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.

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

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

and here:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南…巷孤猫 2024-11-05 06:07:42

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

看一下这个示例:

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

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

更新:

如果默认情况下不起作用,请尝试在 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)");

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

Take a look at this example:

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

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

UPDATE:

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)");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文