包含文件夹和文件的文档库,成功显示具有正确关系的项目,但文件夹层次结构中的文件夹不匹配 http://oi62.tinypic.com/nyembb.jpg
当前项目在文档库中维护,如图A所示,但我的代码生成如图B中所示
using (var site = new SPSite(projectInitiationRequest.ProjectUrl))
{
using (SPWeb web = site.RootWeb)
{
SPDocumentLibrary myDocLib = (SPDocumentLibrary)web.Lists[Constants.ProjectLibrary];
for (int i = 0; i < myDocLib.Folders.Count; i++)
{
TreeNode treeHeadNode = new TreeNode();
treeHeadNode.Text = myDocLib.Folders[i].Name;
treeHeadNode.Value = myDocLib.Folders[i].ID.ToString();
treeHeadNode.ShowCheckBox = false;
treeView1.Nodes.Add(treeHeadNode);
for (int j = 0; j < myDocLib.Items.Count; j++)
{
if (myDocLib.Items[j].File.ParentFolder.Name == myDocLib.Folders[i].Name)
{
TreeNode treeChildNode = new TreeNode();
treeChildNode.Text = myDocLib.Items[j].Name;
treeChildNode.Value = myDocLib.Items[j].ID.ToString();
treeChildNode.NavigateUrl = myDocLib.Items[j].Url;
treeHeadNode.ChildNodes.Add(treeChildNode);
}
}
}
}
}
答案 0 :(得分:0)
@Tarik感谢提示(递归调用)找到了在树视图中加载文件夹,文件层次结构的解决方案
TreeNode node = new TreeNode();
SPDocumentLibrary myDocLib = (SPDocumentLibrary)web.Lists[Constants.ProjectLibrary];
SPFolder root = myDocLib.RootFolder;
string baseURL = web.Url.ToString();
Utilities.GetFolderNode(node, root, baseURL);
node.Text = myDocLib.Title;
node.NavigateUrl = myDocLib.DefaultViewUrl;
treeView1.Nodes.Add(node);
参考:http://www.codeproject.com/Articles/37530/Document-Library-Tree-View-Web-Part-for-SharePoint