SharePoint 2013 Get Document library folder tree structure

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.