通过创建MOSS自定义字段类来实现和基于TREEVIEW的OU菜单

网上一有一篇文章,来很仔细的描述如何增加自定义字段的.可能大家都有见过。这里就不在详细讲如何创建自定义字段了。

有兴趣的话可以查看我BLOG的另外一篇文章http://blog.lickies.cn/Lists/Posts/ViewPost.aspx?ID=17


----------------------------------------
接下来,我来告诉大家如何做TREEVIEW的树型菜单.

首先修改.ASCX文件

<% @ Control Language="C#" Debug="true"%>
<% @ 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"  %>

<SharePoint:RenderingTemplate ID="SelectItemFromXMLFieldControl" runat="server">
    <Template>
   
        <asp:TextBox ID="txt_Ou" runat="server"></asp:TextBox>
     <asp:TreeView ID="TreeView1" runat="server" ShowLines="True">
</asp:TreeView>
    </Template>
</SharePoint:RenderingTemplate>
修改SelectItemFromXML.FieldControl.cs文件
using System;
using System.Runtime.InteropServices;
using System.Web;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web.UI.WebControls;
using System.IO;
using System.Xml;
using System.Diagnostics;
using System.DirectoryServices;


namespace SelectItemFromXML
{
    [CLSCompliant(false)]
    [Guid("eb269bd9-0d3e-4aa2-b88f-37fbccb0d7d8")]
    public class SelectItemFromXMLFieldControl : BaseFieldControl
    {

        protected TreeView TreeView1;
        protected TextBox txt_Ou;
        protected override string DefaultTemplateName
        {
            get
            {
                return "SelectItemFromXMLFieldControl";
            }
        }

        public override object Value
        {
            get
            {
                EnsureChildControls();
                return txt_Ou.Text;
            }
            set
            {
                EnsureChildControls();
                txt_Ou.Text = (string)this.ItemFieldValue;
            }
        }

        public override void Focus()
        {
            EnsureChildControls();
            txt_Ou.Focus();
        }

        protected override void CreateChildControls()
        {
            if (Field == null) return;
            base.CreateChildControls();

            if (ControlMode == Microsoft.SharePoint.WebControls.SPControlMode.Display)
                return;

            txt_Ou = (TextBox)TemplateContainer.FindControl("txt_Ou");
            TreeView1 = (TreeView)TemplateContainer.FindControl("TreeView1");
          
            if (!Page.IsPostBack)
            {             
               
                TreeNode node2 = new TreeNode();
                node2.Text = "泉州移动";
                TreeView1.Nodes.Add(node2);
                GetOu("OU=泉州移动", 10,node2);
               
            }

        }
        protected void TreeView1_SelectNodeChanged(object sender, EventArgs e)
        {

        }
        public void GetOu(string ouname, int amstr,TreeNode nodetmp)
        {
            //获取AD的对象
            //搜索组织单位
            DirectoryEntry entry = new DirectoryEntry("LDAP://SHAREPOINT2007.QZIT.COM", "administrator", "你的密码");
            //获取子结点
            System.DirectoryServices.DirectoryEntry subentry = entry.Children.Find(ouname, "organizationalUnit");
           

            //对子对象进行循环
            foreach (DirectoryEntry res in subentry.Children)
            {
                if (res.Name.Substring(0, 3) == "OU=")//判断是否为OU
                {
                    //增加子结点
                    TreeNode node2 = new TreeNode();
                    node2.Text = res.Name.ToString().Replace("OU=", "") ;
                    nodetmp.ChildNodes.Add(node2);
                    //递归调用
                    GetOu(res.Name.ToString()+","+ouname, 10,node2);
                  
                }
            }

        }
    }
}
其中必须确定在AD根结点下建立一个泉州移动的组织单位(也可修改其中代码)

转载于:https://www.cnblogs.com/lickies/archive/2009/01/22/1379737.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值