• sharepoint 2010 获取列表术语数据源方法


    ①,创建一个webpart,这个webpart里面放一个treeview控件,
    <asp:TreeView ID="TreeView1" runat="server">
    </asp:TreeView>
    ②,引用 Microsoft.SharePoint.Taxonomy.dll
    ③,在后台代码中,添加如下代码。

    protected void Page_Load(object sender, EventArgs e)

            {

                if (!IsPostBack)

                {

    SPSecurity.RunWithElevatedPrivileges(delegate()

                    {

                        SPSite site =SPContext.Current.Site;

                        SPWeb web =SPContext.Current.Web;

                        SPList list = web.Lists["共享文档"];

                        TaxonomySession session =new TaxonomySession(site);

                        TaxonomyField oField = list.Fields["文档标签"]as TaxonomyField;//创建的字段名

                        TreeNode treeNode =new TreeNode();

                        treeNode.Text = "文档标签";

                        TreeView1.Nodes.Add(treeNode);

                        TermSet termSet = session.DefaultSiteCollectionTermStore.GetTermSet(oField.TermSetId);

                        foreach (Term termin termSet.Terms)

                        {

                            AddTermSet(term, treeNode);

                        }

                    });

                }

            }

            void AddTermSet(Term term,TreeNode treeNode)

            {

                var node = new TreeNode(term.Name, term.Id.ToString(),null, "", null);

                treeNode.ChildNodes.Add(node);

                treeNode = node;

                foreach (Term tin term.Terms)

                {

                    AddTermSet(t, treeNode);

                }

            }

  • 相关阅读:
    C# 枚举 字符串 转换
    调用程序中的资源中的图片文件
    将文件的图标添加到LISTVIEW中
    OpenFileDialog
    关于CSS的优先级,CSS优先级计算,多个class引用
    block,inline和inline-block概念和区别
    jQuery之防止冒泡事件
    OOP中的六种关系以及和JDK或框架中源码进行匹配对应
    Linux创建一个周期任务来定期删除过期的文件
    SpringBoot初探
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3074870.html
Copyright © 2020-2023  润新知