开发自己的SQL2005报表查看SharePoint WebPart(二)
2007-02-26 12:20
417 查看
在(一)中,已经完成了一个sharepoint Web part的开发和部署。但是我们的web part还没有任何功能。现在,我们要开始将SQL reporting的报表显示功能加进来了。
访问SQL reporting报表有很多方法,这里我们选用的是调用Web service的方式。
在工程中增加对SQL reporting service的引用, http://ctc-bar:81/ReportServer/reportservice.asmx(ctc-bar:81是报表服务器名称和段口号)
为了简化对报表服务器的调用,我们新建一个ReportAdapter类负责对web service的调用。
using System;
using System.Collections.Generic;
using System.Text;
namespace BARreportWebPart
{
public class ReportAdapter
{
ReportingServer.ReportingService ReportSvr = null;
string reportServerURL = null;
string reportPath = null;
string format = "HTML4.0";
string zoom = "100";
string deviceInfo = "<DeviceInfo></DeviceInfo>";
string encoding = null;
string mimeType = null;
ReportingServer.ParameterValue[] outParameters = null;
ReportingServer.Warning[] warnings = null;
string[] streamIDs = null;
public ReportAdapter(string serverURL,string path)
{
reportServerURL = serverURL;
reportPath = path;
ReportSvr = new ReportingServer.ReportingService();
ReportSvr.Url = reportServerURL;
ReportSvr.Credentials = System.Net.CredentialCache.DefaultCredentials;
}
public ReportingServer.ReportParameter[] GetParameters()
{
return ReportSvr.GetReportParameters(reportPath, null, false, null, null);
}
public byte[] RenderReport(ReportingServer.ParameterValue[] parameterValues)
{
return ReportSvr.Render(reportPath, format, null, deviceInfo, parameterValues, null, null, out encoding, out mimeType, out outParameters, out warnings, out streamIDs);
}
}
}
这个类的构造函数用来指定要访问的报表serverURL是服务器的地址,path是报表的路径
GetParameters()可以返回报表的参数,我们可以自己构造参数输入的UI控件。
RenderReport用来返回查询报表的结果。
然后,我们在web part的render方法中调用ReportAdapter来查询报表
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
namespace BARreportWebPart
{
public class BARreportWebPart : WebPart
{
public BARreportWebPart()
{
}
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
string reportServerURL = "http://ctc-bar:81/ReportServer/ReportService.asmx";
string reportPath = "/BARreports/EBCdetailList";
ReportAdapter rsAdapter = new ReportAdapter(reportServerURL, reportPath);
ReportingServer.ReportParameter[] parameters = rsAdapter.GetParameters();
ReportingServer.ParameterValue[] parameterValues = null;
if (parameters.Length > 0)
{
parameterValues = new ReportingServer.ParameterValue[parameters.Length];
for (int i = 0; i < parameters.Length; i++)
{
parameterValues[i] = new ReportingServer.ParameterValue();
parameterValues[i].Name = parameters[i].Name;
parameterValues[i].Label = parameters[i].Prompt;
}
parameterValues[0].Value = "2007-1-1";
parameterValues[1].Value = "2007-3-1";
}
System.Text.Encoding enc = System.Text.Encoding.UTF8;
byte[] result = rsAdapter.RenderReport(parameterValues);
string htmlResult = enc.GetString(result);
//htmlResult = htmlResult.Replace(reportServerURL.Replace("/ReportService.asmx", "?"), "http://" & Request("SERVER_NAME") & Request("SCRIPT_NAME") & "?Report=");
writer.Write(htmlResult);
}
}
}
访问SQL reporting报表有很多方法,这里我们选用的是调用Web service的方式。
在工程中增加对SQL reporting service的引用, http://ctc-bar:81/ReportServer/reportservice.asmx(ctc-bar:81是报表服务器名称和段口号)
为了简化对报表服务器的调用,我们新建一个ReportAdapter类负责对web service的调用。
using System;
using System.Collections.Generic;
using System.Text;
namespace BARreportWebPart
{
public class ReportAdapter
{
ReportingServer.ReportingService ReportSvr = null;
string reportServerURL = null;
string reportPath = null;
string format = "HTML4.0";
string zoom = "100";
string deviceInfo = "<DeviceInfo></DeviceInfo>";
string encoding = null;
string mimeType = null;
ReportingServer.ParameterValue[] outParameters = null;
ReportingServer.Warning[] warnings = null;
string[] streamIDs = null;
public ReportAdapter(string serverURL,string path)
{
reportServerURL = serverURL;
reportPath = path;
ReportSvr = new ReportingServer.ReportingService();
ReportSvr.Url = reportServerURL;
ReportSvr.Credentials = System.Net.CredentialCache.DefaultCredentials;
}
public ReportingServer.ReportParameter[] GetParameters()
{
return ReportSvr.GetReportParameters(reportPath, null, false, null, null);
}
public byte[] RenderReport(ReportingServer.ParameterValue[] parameterValues)
{
return ReportSvr.Render(reportPath, format, null, deviceInfo, parameterValues, null, null, out encoding, out mimeType, out outParameters, out warnings, out streamIDs);
}
}
}
这个类的构造函数用来指定要访问的报表serverURL是服务器的地址,path是报表的路径
GetParameters()可以返回报表的参数,我们可以自己构造参数输入的UI控件。
RenderReport用来返回查询报表的结果。
然后,我们在web part的render方法中调用ReportAdapter来查询报表
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
namespace BARreportWebPart
{
public class BARreportWebPart : WebPart
{
public BARreportWebPart()
{
}
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
string reportServerURL = "http://ctc-bar:81/ReportServer/ReportService.asmx";
string reportPath = "/BARreports/EBCdetailList";
ReportAdapter rsAdapter = new ReportAdapter(reportServerURL, reportPath);
ReportingServer.ReportParameter[] parameters = rsAdapter.GetParameters();
ReportingServer.ParameterValue[] parameterValues = null;
if (parameters.Length > 0)
{
parameterValues = new ReportingServer.ParameterValue[parameters.Length];
for (int i = 0; i < parameters.Length; i++)
{
parameterValues[i] = new ReportingServer.ParameterValue();
parameterValues[i].Name = parameters[i].Name;
parameterValues[i].Label = parameters[i].Prompt;
}
parameterValues[0].Value = "2007-1-1";
parameterValues[1].Value = "2007-3-1";
}
System.Text.Encoding enc = System.Text.Encoding.UTF8;
byte[] result = rsAdapter.RenderReport(parameterValues);
string htmlResult = enc.GetString(result);
//htmlResult = htmlResult.Replace(reportServerURL.Replace("/ReportService.asmx", "?"), "http://" & Request("SERVER_NAME") & Request("SCRIPT_NAME") & "?Report=");
writer.Write(htmlResult);
}
}
}
相关文章推荐
- 开发自己的SQL2005报表查看SharePoint WebPart (转)
- 开发自己的SQL2005报表查看SharePoint WebPart
- 开发自己的SQL2005报表查看SharePoint WebPart(一)
- 开发自己的SQL2005报表查看SharePoint WebPart(三)
- 开发自己的SQL2005报表查看SharePoint WebPart(四)
- 开发自己的SQL2005报表查看SharePoint WebPart
- SharePoint PowerShell部署开发好的WebPart到服务器上
- 在Office SharePoint Server 2007上创建自己的WebPart!
- 用于 Microsoft SharePoint 技术的 Microsoft SQL Server 2005 Reporting Services 外接程序
- SharePoint WebPart开发实战(一):定制属性及配置界面
- [推荐WebPart开发教程]Developing Web Parts for SharePoint Portal Server 2003 in .NET
- (Asp.net,ms sqlserver embbed 2005 edition,windows sharepoint services)安装windows sharepoint service惊魂记
- SharePoint WebPart开发实战(一):定制属性及配置界面
- 利用Visual Studio 2005 Extensions for Windows SharePoint Services 3.0开发,部署时发现的一个怪现象
- sharepoint webpart开发中遇到的问题 This type of page is not served.
- Visual Studio 2005部署SharePoint WebPart失败的原因
- SharePoint WebPart开发步骤
- Sharepoint Webpart开发记录
- Tip - SharePoint + RDLC (SQL客户端报表)
- sharepoint potal server 开发 webpart中, toolpart用模态对话框传参