sharepoint 2013 获取文档库文件夹树形结构
在做sharepoint 2013或者sharepoint 2010文档库的过程中,经常会建很多的文件夹,不同类别存储不同文件,相当于文档的分类,这里主要是记录一下,将文档库的文件夹结构,绑定到treeview。
protected void Page_Load(object sender,EventArgse)
{
if(!Page.IsPostBack)
{
BindData();
}
}
private void BindData()
{
SPSite site =new SPSite("http://win2012sp/");
SPWeb spWeb = site.OpenWeb();
SPList spList = spWeb.Lists["共享文档"];
tvTreeCatalog.Nodes.Add(CreateNodeByList(spList));
spWeb.Dispose();
}
private TreeNode CreateNodeByList(SPListspList)
{
TreeNode node =new TreeNode();
node.Text = spList.Title;
node.Value = spList.RootFolder.Url;
foreach(SPFolder subFolderinspList.RootFolder.SubFolders)
{
if(subFolder.Name !="Forms")
{
node.ChildNodes.Add(CreateNodeByFolder(subFolder));
}
}
returnnode;
}
private TreeNode CreateNodeByFolder(SPFolderspFolder)
{
TreeNode node =new TreeNode();
node.Text = spFolder.Name;
node.NavigateUrl = SPContext.Current.Web.Lists["共享文档1"].DefaultViewUrl+"?RootFolder="+spFolder.Url;
node.ImageUrl = SPControl.GetContextWeb(Context).Url+"/_layouts/images/folder.gif";
foreach(SPFolder subFolderinspFolder.SubFolders)
{
node.ChildNodes.Add(CreateNodeByFolder(subFolder));
}
returnnode;
}
补充:软件开发 , Java ,