显示来自报表服务PDF文件 [英] Display a PDF from Reporting Services
问题描述
我想显示从我的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.
有一个简单的办法做到这一点只使用网址是什么?
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 /报告服务/ 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:\test\test123.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)");
这篇关于显示来自报表服务PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!