下面我这个例子是做一个usercontrol.ascx的用户控件,把一个使用asp.net开发的webusercontrol使用moss的webpart包装,然后放到moss中
2、 修改usercontrol.ascx 代码,如下:
<%@ control language="C#" autoeventwireup="true" inherits="LoginOA_Control, WebSite_deploy" %>
<%@ Assembly Name="Microsoft.SharePoint, Version=
<%@ Register TagPrefix="SharePoint" Assembly="Microsoft.SharePoint, Version=
然后把修改后的usercontrol.ascx 拷贝到C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\CONTROLTEMPLATES目录下面。
把WebSite_deploy.dll文件拷贝到要部署的网站目录下面,
如:C:\Inetpub\wwwroot\wss\VirtualDirectories\8080\_app_bin,这样usercontrol部分就开发完了,下面我们做一个webpart来包装这个userctronl.ascx文件
3、 打开vs2005 新建一个webpart,然后重写2个方法,代码如下:
protected override void Render(HtmlTextWriter writer)
{
userControl.RenderControl(writer);
}
protected override void CreateChildControls()
{
base.CreateChildControls();
userControl = (UserControl)Page.LoadControl(@"~/_controltemplates/LoginOA_Control.ascx");//导入userctronl.ascx文件
Controls.Add(userControl);
}
Webpart开发完毕后,直接部署到moss网站上,然后进入网站页面,添加刚才的webpart,就可以看到usercontrol.ascx这个页面了
下面是我做的全部代码:
Webpart 的SsoControl.cs类代码:
using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using System.IO;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using System.Web.UI.WebControls;
namespace SsoControl
{
[Guid("24162848
public class SsoControl : System.Web.UI.WebControls.WebParts.WebPart
{
UserControl userControl;
public SsoControl()
{
this.ExportMode = WebPartExportMode.All;
}
protected override void Render(HtmlTextWriter writer)
{
userControl.RenderControl(writer);
}
protected override void CreateChildControls()
{
base.CreateChildControls();
userControl = (UserControl)Page.LoadControl(@"~/_controltemplates/LoginOA_Control.ascx");
Controls.Add(userControl);
}
}
}
userControl.ascx代码:
<%@ control language="C#" autoeventwireup="true" inherits="LoginOA_Control, WebSite_deploy" %>
<%@ Assembly Name="Microsoft.SharePoint, Version=
<%@ Register TagPrefix="SharePoint" Assembly="Microsoft.SharePoint, Version=
<table border="0" cellpadding="0" cellspacing="0" style="width:200px; height: 100%">
<tr>
<td style="height:30px" align="right">
<table border="0" cellpadding="0" cellspacing="0" style="width:100%">
<tr>
<td align="right">
<img style=" border:none; vertical-align:bottom" src="/_layouts/IMAGES/OAControl/point_banner_left.gif" alt="" />
</td>
<td style="width:82px">
<img src="/_layouts/IMAGES/OAControl/ba_index.gif" alt="" />
</td>
<td style="width:65px">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top" >
<table border="0" cellpadding="0" cellspacing="0" style="width:100%">
<tr>
<td valign="top" style="height: 302px">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</td>
<td valign="bottom" style="height: 302px; width:85px">
<img src="/_layouts/IMAGES/OAControl/obj_arrow.gif" alt=""/>
</td>
</tr>
</table>
</td>
</tr>
</table>
<%@ control language="C#" autoeventwireup="true" inherits="LoginOA_Control, WebSite_deploy" %>
<%@ Assembly Name="Microsoft.SharePoint, Version=
<%@ Register TagPrefix="SharePoint" Assembly="Microsoft.SharePoint, Version=
<table border="0" cellpadding="0" cellspacing="0" style="width:200px; height: 100%">
<tr>
<td style="height:30px" align="right">
<table border="0" cellpadding="0" cellspacing="0" style="width:100%">
<tr>
<td align="right">
<img style=" border:none; vertical-align:bottom" src="/_layouts/IMAGES/OAControl/point_banner_left.gif" alt="" />
</td>
<td style="width:82px">
<img src="/_layouts/IMAGES/OAControl/ba_index.gif" alt="" />
</td>
<td style="width:65px">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top" >
<table border="0" cellpadding="0" cellspacing="0" style="width:100%">
<tr>
<td valign="top" style="height: 302px">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</td>
<td valign="bottom" style="height: 302px; width:85px">
<img src="/_layouts/IMAGES/OAControl/obj_arrow.gif" alt=""/>
</td>
</tr>
</table>
</td>
</tr>
</table>