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

发布于 2024-12-08 01:01:30 字数 2109 浏览 0 评论 0原文

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

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

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

然而,将 ASP.Net Web 应用程序发布到 Web 服务器后,会遇到问题;

在 Web 服务器上重新创建带有文档的公用文件夹 - 我的期望是该过程将以与我的 PC 上的过程相同的方式进行;

ASP.Net TreeView 的填充工作正常;但是,如果选择了 TreeView 节点 - 从 TreeView 中选择的文档不会显示;

代码片段如下;预先感谢您的任何见解!最好的问候 - 罗布

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;
            }
        }

I am working with an ASP.Net TreeView control, and I load the Treeview dynamically with C#;

Utilizing an iFrame, a document is displayed in an iFrame - based on TreeNode selection;

All is OK on my PC, and the document displays properly from a public drive in the network;

However, after publishing the ASP.Net web application to a web server, issues are encountered;

Re-creating the public folder, with documents, on the web server - my expectation was the process would work in the same fashion as the process works on my PC;

The population of the ASP.Net TreeView works OK; However, if a TreeView node is selected - the document selected from the TreeView does not display;

Code snippets are below; Thanks in advance for any insight! Best regards - 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;
            }
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青衫负雪 2024-12-15 01:01:30

看起来像这一行:

var src = this.TreeView1.SelectedValue;

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

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

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

Looks like this line:

var src = this.TreeView1.SelectedValue;

Will always hold the physical path to the file because of the way you add the values:

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

Therefore, when you set the src property to the iframe you should map the src to the virtual directory where your app is hosted

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文