</asp:TreeView>
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);
}
}