标签:
在做sharepoint 2013或者sharepoint 2010文档库的过程中,经常会建很多的文件夹,不同类别存储不同文件,相当于文档的分类,这里主要是记录一下,将文档库的文件夹结构,绑定到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["共享文档"];
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["共享文档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;
}
标签:
原文地址:http://www.cnblogs.com/ningang/p/4321980.html