报告服务:获取生成的报告的PDF [英] Reporting services: Get the PDF of a generated report

查看:133
本文介绍了报告服务:获取生成的报告的PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经有一些已经运行报告Reporting Services服务器,而我现在需要通过自定义网站生成它们(运行asp.net MVC3)。

I've a reporting services server which has already some running reports, and I need now to generate them through a custom website(running asp.net MVC3).

我要检索该报告作为流/字节将其发送给用户。无报告查看器左右。

I need to retrieve this report as stream/byte to send it to the user. No "report viewer" or so.

我最后一次使用报告服务是使用SQL 2005年,我们应当广告作为参照一个不起眼的ASMX文件。

Last time I used reporting services was with sql 2005, and We should ad as reference an obscure asmx file.

什么是对,现在,随着SQL Server报告2008 R2,.NET4和Visual Studio 2010?我无法找到一个教程解释了整个事情。

What's about now, with sql server reporting 2008 R2, .Net4 and visual studio 2010? I can't find a tutorial explaining the whole thing.

(其实我无法找到一个教程那里是为SQL 2008 R2无报告查看器)

(in fact I can't find a tutorial where there is no report viewer for sql 2008 r2)

推荐答案

MSDN 。我已经使用 URL访问经常在ASP快速简单的PDF按钮.NET应用程序。

Several methods are provided at MSDN. I have used URL access often for quick simple PDF buttons in an ASP .NET app.

下面是这样code的快速黑客位。它可以清理使用集成身份验证,并且有很多方法,你可以存储报告名称。 (我切和一些旧code我将报告存储到数据库,然后后来可能返回从数据库中粘贴此。

Here's a quick hack bit of code doing this. It could be cleaned up to use integrated authentication, and there are many ways you could store the report name. (I cut and pasted this from some old code I had that would store a report to a database and then later could return that from the db.

// First read in the report into memory.

string strReportUser = "RSUserName";
string strReportUserPW = "MySecretPassword";
string strReportUserDomain = "DomainName";

string sTargetURL = "http://SqlServer/ReportServer?" +
   "/MyReportFolder/Report1&rs:Command=Render&rs:format=PDF&ReportParam=" +
   ParamValue;

HttpWebRequest req =
      (HttpWebRequest)WebRequest.Create( sTargetURL );
req.PreAuthenticate = true;
req.Credentials = new System.Net.NetworkCredential(
    strReportUser,
    strReportUserPW,
    strReportUserDomain );

HttpWebResponse HttpWResp = (HttpWebResponse)req.GetResponse();

Stream fStream = HttpWResp.GetResponseStream();

HttpWResp.Close();



//Now turn around and send this as the response..
byte[] fileBytes = ReadFully( fStream );
// Could save to a database or file here as well.

Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader(
    "content-disposition",
    "attachment; filename=\"Report For " +
        ParamValue + ".pdf\"" );
Response.BinaryWrite( fileBytes );
Response.Flush();
Response.End();

的readFully是

ReadFully is

public static byte[] ReadFully( Stream input )
{
   using ( MemoryStream ms = new MemoryStream() )
   {
      input.CopyTo( ms );
      return ms.ToArray();
   }
}  

这篇关于报告服务:获取生成的报告的PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆