C# 显示来自Reporting Services的PDF
我想从我的WinForms应用程序中显示Reporting Services生成的PDF 我尝试了以下方法:C# 显示来自Reporting Services的PDF,c#,pdf,reporting-services,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()); 它启动浏览器,然后依次提示我打开或保存此文件 理想情况下,我只想在浏览器或PDF查看器中显示文件。
Uri uri = new Uri("http://myReportServer?MyReport&rs%3aCommand=Render&rs:Format=pdf");
System.Diagnostics.Process.Start(uri.ToString());
它启动浏览器,然后依次提示我打开或保存此文件
理想情况下,我只想在浏览器或PDF查看器中显示文件。问题是我必须同时打开浏览器和PDF查看器,这是用户不想要的
有没有一种简单的方法可以使用URL来实现这一点
我的另一个选择是写一些看起来很简单的C代码。这里有一些例子:
在这里:
您可以将PDF下载到磁盘,然后使用Process。开始显示它 看看这个例子:
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()之前:
谢谢,看起来不错,但是我尝试了一下,得到了以下错误“远程服务器返回了一个错误:(401)未经授权。”我的原始代码没有收到任何错误。有什么我需要做的吗?@HABAN,很遗憾我无法访问所有的用户密码。我能做些什么来确保使用集成身份验证吗?@HABAN,好的,我知道了:webClient.Credentials=CredentialCache.DefaultCredentials;我目前正在尝试同样的事情,并收到403(禁止)。在本地工作,但不在生产中。URL在粘贴到浏览器中时起作用。知道为什么吗?已经尝试了一些用户代理并设置了代理凭据。
wcli.Credentials = new NetworkCredential("username", "password", "domain");
wcli.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");