开发者

Display a PDF from Reporting Services

I would like to display a PDF generated from Repor开发者_如何转开发ting 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


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)");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜