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

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

问题描述

我有一个报告服务服务器,它已经有一些正在运行的报告,我现在需要通过自定义网站(运行 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 .NET 应用程序中的简单 PDF 按钮.

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

这是执行此操作的快速破解代码.可以清理它以使用集成身份验证,并且可以通过多种方式存储报告名称.(我从我拥有的一些旧代码中剪切并粘贴了这个,这些代码将报告存储到数据库,然后可以从数据库返回.

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();




//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();
HttpWResp.Close();
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天全站免登陆