I like the managed meta data browsing in SharePoint 2010 that you get against a library.
My wish to to put something like this into a web part and this has worked with one problem.
So going back to managed meta data browsing by library.
This is fulfilled by MetadataNavTree.ascx
Taking a peek at this gives us an idea to create this tree in a web part.
So in my visual web part I have.
<SharePoint:SPHierarchyDataSourceControl runat="server"
ID="MMTreeViewDataSource"
IncludeDiscussionFolders="false"
ShowListChildren="true"
/>
<OfficeServer:MetadataHierarchyDataSourceControl runat="server"
ID="MetadataTreeViewDataSource"
SPHierarchyDataSourceId="MMTreeViewDataSource"
/>
<SharePoint:SPRememberScroll runat="server" id="TreeViewRememberScroll" onscroll="javascript:_spRecordScrollPositions(this);"
style="overflow-y: auto; overflow-x: hidden;">
<SharePoint:SPTreeView runat="server"
ID="MMTreeView"
ShowLines="false"
DataSourceID="MetadataTreeViewDataSource"
Other stuff....
OnTreeNodeDataBound="MMTreeView_TreeNodeDataBound" >
</SharePoint:SPTreeView>
</SharePoint:SPRememberScroll>
And in my code behind I have.
protected void Page_Load(object sender, EventArgs e)
{
// When the page is loaded ensure that data source is bound to the correct list
MMTreeViewDataSource.RootListId = ucpListID;
MMTreeViewDataSource.RootWebId = ucpWebID;
MMTreeView.ExpandDepth = ucpExpandDepth;
}
This deploys as a web part and renders the managed meta data structure configured against the list (identified by RootListID) perfectly. I can then override OnTreeNodeDataBound and make the links generated do something useful.
The odd problem is that unless the web part is deployed to a page in the RootWeb then it does not render.
This is because OfficeServer:MetadataHierarchyDataSourceControl will not return results when used in the above manner unless in the rootweb. I tried using rootwebid and rootlistids from the same web as I deploy the webpart in but to no avail.
Any suggestions?