愚见未来

人的思想时时刻刻都在进步,如果你早上起床,想起昨天所做的事情是那么幼稚和迂腐,那么恭喜你,你又变得成熟一点了!
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

开发 Moss webpart

Posted on 2009-12-25 13:36  愚见未来  阅读(293)  评论(0编辑  收藏  举报

下面我这个例子是做一个usercontrol.ascx的用户控件,把一个使用asp.net开发的webusercontrol使用moss的webpart包装,然后放到moss中 使用的过程,这个以前就有好多人都写过了,不过我认为这种方式还是不错的,开发起来简便,所以发出来共享下:

 

1、  vs2005中新建一个网站,新建一个usercontrol.ascx文件,然后写代码完成需要的功能,然后发布网站,把usercontrol.ascx..cs文件编译成WebSite_deploy.dll文件。

2、  修改usercontrol.ascx 代码,如下:

 

<%@ control language="C#" autoeventwireup="true" inherits="LoginOA_Control, WebSite_deploy" %>

<%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Register TagPrefix="SharePoint" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.WebControls"  %>

然后把修改后的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-50f3-408d-bbf0-eb1d0867116b")]

    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=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Register TagPrefix="SharePoint" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.WebControls"  %>

 

<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>

 

 修改后的usercontrol.ascx文件代码:

<%@ control language="C#" autoeventwireup="true" inherits="LoginOA_Control, WebSite_deploy" %>

 

<%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Register TagPrefix="SharePoint" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.WebControls"  %>

 

<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>