开发自己的SQL2005报表查看SharePoint WebPart(三)
2007-02-26 15:42
447 查看
我们在(一)里完成了web part的实现
在(二)里完成了通过调用SQL2005 reporting services的web service,查询并显示报表
现在,我们要给Web part增加属性来设置报表服务器的地址和报表路径
首先,为了能够在SharePoint中设置属性,需要增加对Microsoft.SharePoint的引用,原来我们的BARreportWebPart是从System.Web.UI.WebControls.WebParts.WebPart继承的,现在要改为从Microsoft.SharePoint.WebPartPages.WebPart继承。否则你在Sharepoint web part属性设置里面看不到你的自定义属性
然后,增加两个字符类型的属性:ReportServerURL,ReportPath。具体的attribute设置请参考
如何给Web part增加自定义属性Creating a Web Part with Custom Properties(http://msdn2.microsoft.com/en-us/library/ms948927.aspx)
这是最后的代码
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint.WebPartPages;
namespace BARreportWebPart
{
[DefaultProperty("Text"),
ToolboxData("<{0}:BARreportWebPart runat=server></{0}:BARreportWebPart>"),
XmlRoot(Namespace = "BARreportWebPart")]
public class BARreportWebPart : Microsoft.SharePoint.WebPartPages.WebPart//System.Web.UI.WebControls.WebParts.WebPart
{
string _reportServerURL="";// = "http://ctc-bar:81/ReportServer/ReportService.asmx";
string _reportPath = "";// = "/BARreports/EBCdetailList";
public BARreportWebPart()
{
}
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
if (string.Empty == ReportServerURL.Trim() || null == ReportServerURL
|| string.Empty == ReportPath.Trim() || null == ReportPath)
{
writer.Write("please set the ReportServerURL, ReportPath");
return;
}
string reportServerURL = ReportServerURL;
string reportPath = ReportPath;
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);
}
// Creates a custom property :
// This property will be displayed as a text box in the
// property pane.
// Create a custom category in the property sheet.
//[Category("Custom Properties")]
// Assign the default value.
[DefaultValue("http://ctc-bar:81/ReportServer/ReportService.asmx")]
// Property is available in both Personalization
// and Customization mode.
[WebPartStorage(Storage.Personal)]
// The caption that appears in the property sheet.
[FriendlyNameAttribute("ReportServerURL")]
// The tool tip that appears when pausing the mouse pointer over
// the friendly name in the property pane.
[Description("Report Server URL: (like http://ctc-bar:81/ReportServer/ReportService.asmx )")]
// Display the property in the property pane.
[Browsable(true)]
[XmlElement(ElementName = "ReportServerURL")]
// The accessor for this property.
public string ReportServerURL
{
get
{
return _reportServerURL;
}
set
{
_reportServerURL = value;
}
}
// Assign the default value.
[DefaultValue("")]
// Property is available in both Personalization
// and Customization mode.
[WebPartStorage(Storage.Personal)]
// The caption that appears in the property sheet.
[FriendlyNameAttribute("ReportPath")]
// The tool tip that appears when pausing the mouse pointer over
// the friendly name in the property pane.
[Description("Report Path")]
// Display the property in the property pane.
[Browsable(true)]
[XmlElement(ElementName = "ReportPath")]
// The accessor for this property.
public string ReportPath
{
get{
return _reportPath;
}
set {
_reportPath = value;
}
}
}
}
在(二)里完成了通过调用SQL2005 reporting services的web service,查询并显示报表
现在,我们要给Web part增加属性来设置报表服务器的地址和报表路径
首先,为了能够在SharePoint中设置属性,需要增加对Microsoft.SharePoint的引用,原来我们的BARreportWebPart是从System.Web.UI.WebControls.WebParts.WebPart继承的,现在要改为从Microsoft.SharePoint.WebPartPages.WebPart继承。否则你在Sharepoint web part属性设置里面看不到你的自定义属性
然后,增加两个字符类型的属性:ReportServerURL,ReportPath。具体的attribute设置请参考
如何给Web part增加自定义属性Creating a Web Part with Custom Properties(http://msdn2.microsoft.com/en-us/library/ms948927.aspx)
这是最后的代码
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint.WebPartPages;
namespace BARreportWebPart
{
[DefaultProperty("Text"),
ToolboxData("<{0}:BARreportWebPart runat=server></{0}:BARreportWebPart>"),
XmlRoot(Namespace = "BARreportWebPart")]
public class BARreportWebPart : Microsoft.SharePoint.WebPartPages.WebPart//System.Web.UI.WebControls.WebParts.WebPart
{
string _reportServerURL="";// = "http://ctc-bar:81/ReportServer/ReportService.asmx";
string _reportPath = "";// = "/BARreports/EBCdetailList";
public BARreportWebPart()
{
}
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
if (string.Empty == ReportServerURL.Trim() || null == ReportServerURL
|| string.Empty == ReportPath.Trim() || null == ReportPath)
{
writer.Write("please set the ReportServerURL, ReportPath");
return;
}
string reportServerURL = ReportServerURL;
string reportPath = ReportPath;
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);
}
// Creates a custom property :
// This property will be displayed as a text box in the
// property pane.
// Create a custom category in the property sheet.
//[Category("Custom Properties")]
// Assign the default value.
[DefaultValue("http://ctc-bar:81/ReportServer/ReportService.asmx")]
// Property is available in both Personalization
// and Customization mode.
[WebPartStorage(Storage.Personal)]
// The caption that appears in the property sheet.
[FriendlyNameAttribute("ReportServerURL")]
// The tool tip that appears when pausing the mouse pointer over
// the friendly name in the property pane.
[Description("Report Server URL: (like http://ctc-bar:81/ReportServer/ReportService.asmx )")]
// Display the property in the property pane.
[Browsable(true)]
[XmlElement(ElementName = "ReportServerURL")]
// The accessor for this property.
public string ReportServerURL
{
get
{
return _reportServerURL;
}
set
{
_reportServerURL = value;
}
}
// Assign the default value.
[DefaultValue("")]
// Property is available in both Personalization
// and Customization mode.
[WebPartStorage(Storage.Personal)]
// The caption that appears in the property sheet.
[FriendlyNameAttribute("ReportPath")]
// The tool tip that appears when pausing the mouse pointer over
// the friendly name in the property pane.
[Description("Report Path")]
// Display the property in the property pane.
[Browsable(true)]
[XmlElement(ElementName = "ReportPath")]
// The accessor for this property.
public string ReportPath
{
get{
return _reportPath;
}
set {
_reportPath = value;
}
}
}
}
相关文章推荐
- 开发自己的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用模态对话框传参