1

我正在使用 ASP.net 树视图将 windows 文件夹映射到树视图。我面临的问题是文件夹结构,映射并成功运行,但文件夹中的文件映射到网页,而不是打开onclick树节点。

请在下面找到我的代码:

if (!IsPostBack)
    {
        String directoryPath = "O:\\Quality\\01.QMS";
        DirectoryInfo directoryInfo = new
        System.IO.DirectoryInfo(directoryPath);
        if (directoryInfo != null)
        {
            TreeNode parentnode1 = null;
            TreeNode rootDirectoryNode =
            CreateTreeView(directoryInfo, parentnode1);
            if (rootDirectoryNode != null)
                TreeView1.Nodes.Add(rootDirectoryNode);
        }
    }


public TreeNode CreateTreeView(DirectoryInfo directoryInfo, TreeNode Node)
{
    TreeNode baseNode = new TreeNode(directoryInfo.Name);
    DirectoryInfo[] subDirectories =
    directoryInfo.GetDirectories();
    FileInfo[] filesInDirectory = directoryInfo.GetFiles();
    for (int i = 0, n = subDirectories.Length; i < n; i++)
        CreateTreeView(subDirectories[i], baseNode);
    for (int ctr = 0, cnt = filesInDirectory.Length; ctr < cnt;
    ctr++)
    {
        TreeNode childNode = new
        TreeNode(filesInDirectory[ctr].Name);
        baseNode.ChildNodes.Add(childNode);
    }
    if (Node == null)
        return baseNode;
    Node.ChildNodes.Add(baseNode);
    return Node;
}
4

0 回答 0