开发者

ASP.Net Treeview Control not displaying documents in iFrame on web server

开发者 https://www.devze.com 2023-04-10 07:26 出处:网络
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;

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消