显示Reporting Services中的PDF

ope*_*hac 5 c# pdf reporting-services

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

我尝试了以下方法:

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

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

理想情况下,我想在浏览器或PDF查看器中仅显示该文件.问题是我必须打开浏览器,然后打开用户不想要的PDF查看器.

有没有一种简单的方法只使用URL来做到这一点?

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

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

和这里:

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

HAB*_*JAN 4

您可以将 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);
Run Code Online (Sandbox Code Playgroud)

更新:

如果默认情况下这不起作用,请尝试在 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)");
Run Code Online (Sandbox Code Playgroud)