SharePoint 2013 Get document library folder tree structureCategory: SharePoint2013-07-15 06:40 5816 People read comments (0) favorite reports
In the process of doing SharePoint 2013 or the SharePoint 2010 document library, often many folders are built, different categories store different files, equivalent to the classification of documents, here is the main record, the document library folder structure, binding to the TreeView.
protected void Page_Load (object Sender,eventargse)
{
if (! Page.IsPostBack)
{
Binddata ();
}
}
private void Binddata ()
{
SPSite site =newspsite ("http://win2012sp/");
SPWeb SPWeb = site. OpenWeb ();
SPList SPList = spweb.lists["shared document"];
TVTREECATALOG.NODES.ADD (Createnodebylist (spList));
Spweb.dispose ();
}
Private TreeNode createnodebylist (SPList SPList)
{
TreeNode node =newtreenode ();
Node. Text = Splist.title;
Node. Value = SPLIST.ROOTFOLDER.URL;
foreach (SPFolder subfolder in SpList.RootFolder.SubFolders)
{
if (subfolder.name! = "Forms")
{
Node. Childnodes.add (Createnodebyfolder (subfolder));
}
}
return node;
}
Private TreeNode Createnodebyfolder (Spfolderspfolder)
{
TreeNode node =newtreenode ();
Node. Text = Spfolder.name;
Node. NAVIGATEURL = spcontext.current.web.lists["shared document 1"]. defaultviewurl+ "? Rootfolder= "+spfolder.url;
Node. IMAGEURL = Spcontrol.getcontextweb (Context). url+ "/_layouts/images/folder.gif";
foreach (SPFolder subfolder in Spfolder.subfolders)
{
Node. Childnodes.add (Createnodebyfolder (subfolder));
}
return node;
}
SharePoint 2013 Get document library folder tree structure