ASP.Net Treeview Control不在Web服务器上的iFrame中显示文档

时间:2011-10-04 13:59:35

标签: asp.net treeview

我正在使用ASP.Net TreeView控件,并使用C#动态加载Treeview;

利用iFrame,文档显示在iFrame中 - 基于TreeNode选择;

我的电脑上的一切正常,文档可以从网络中的公共驱动器正确显示;

但是,在将ASP.Net Web应用程序发布到Web服务器之后,遇到了问题;

在Web服务器上重新创建带有文档的公共文件夹 - 我期望这个过程的工作方式与我在PC上的过程相同;

ASP.Net TreeView的数量正常;但是,如果选择了TreeView节点,则不会显示从TreeView中选择的文档;

代码片段如下;提前感谢任何见解!最好的问候 - Rob

private void BuildTree()
{
DirectoryInfo rootDir = new DirectoryInfo(Server.MapPath("./Customers/Associated Food Stores/"));
TreeNode rootNode = new TreeNode(rootDir.Name, rootDir.FullName);
            TreeView1.Nodes.Add(rootNode);

            //begin recursively traversing the directory structure
            TraverseTree(rootDir, rootNode);
        }

private void TraverseTree(DirectoryInfo currentDir, TreeNode currentNode)
        {
            //loop through each sub-directory in the current one
            foreach (DirectoryInfo dir in currentDir.GetDirectories())
            {
                //create node and add to the tree view
                TreeNode node = new TreeNode(dir.Name, dir.FullName);
                currentNode.ChildNodes.Add(node);

                foreach (System.IO.FileInfo f in dir.GetFiles("*.*"))
                {
                    TreeNode nodeFile = new TreeNode(f.Name, f.FullName);
                    currentNode.ChildNodes.Add(nodeFile);
                }

                //recursively call same method to go down the next level of the tree
                TraverseTree(dir, node);
            }

            TreeView1.CollapseAll();

            //TreeView1.NodeIndent = 15;

        }

        protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
        {
            //this.Label1.Text = "Selected Node changed to: " + this.TreeView1.SelectedNode.Text;
            var src = this.TreeView1.SelectedValue;

            if (this.TreeView1.SelectedValue.EndsWith("pdf"))
            {
                myPDF.Attributes["src"] = src;
                myPDF.Visible = true;

                btnClose.Visible = true;
            }
        }

1 个答案:

答案 0 :(得分:1)

看起来像这一行:

var src = this.TreeView1.SelectedValue;

由于添加值的方式,将始终保留文件的物理路径:

TreeNode nodeFile = new TreeNode(f.Name, f.FullName);

因此,当您将src属性设置为iframe时,您应该将src映射到托管应用的虚拟目录