ASP.Net Treeview 控件不显示 Web 服务器上 iFrame 中的文档
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来像这一行:
由于添加值的方式,将始终保留文件的物理路径:
因此,当您将
src
属性设置为iframe
时,您应该将 src 映射到托管应用程序的虚拟目录Looks like this line:
Will always hold the physical path to the file because of the way you add the values:
Therefore, when you set the
src
property to theiframe
you should map the src to the virtual directory where your app is hosted