Hej
Jeg har fået splejset noget kode sammen jeg har fundet på nettet, til en hjemmelavet FAQ, jeg har fået det meste til at virke, men mangler at kunne vise siderne ordenligt.
Jeg har en folder struktur hvor hver mappe er et emne, og hver .html fil er en side under et emne.
Mit problem er at de links som mit treeview laver, ikke virker, men det viser fint nok mapper og filerne i mapperne..
c#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class NewFAQ_Howtos_treeview_new : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
System.IO.DirectoryInfo RootDir = new System.IO.DirectoryInfo("\\\\10.46.0.13\\supportsidedata$\\NewFAQ\\pages");
TreeView TV = new TreeView();
// output the directory into a node
TreeNode RootNode = OutputDirectory(RootDir, null);
// add the output to the tree
TV.Nodes.Add(RootNode);
//TV.CollapseAll();
//adding the Tree View control to our Panel.
pnl.Controls.Add(TV);
}
}
TreeNode OutputDirectory(System.IO.DirectoryInfo directory, TreeNode parentNode)
{
// validate param
if (directory == null) return null;
// create a node for this directory
TreeNode DirNode = new TreeNode(directory.Name);
// get subdirectories of the current directory
System.IO.DirectoryInfo[] SubDirectories = directory.GetDirectories();
// output each subdirectory
for (int DirectoryCount = 0; DirectoryCount < SubDirectories.Length; DirectoryCount++)
{
OutputDirectory(SubDirectories[DirectoryCount], DirNode);
}
// output the current directories files
System.IO.FileInfo[] Files = directory.GetFiles();
for (int FileCount = 0; FileCount < Files.Length; FileCount++)
{
DirNode.ChildNodes.Add(new TreeNode(Files[FileCount].Name));
}
// if the parent node is null, return this node
// otherwise add this node to the parent and return the parent
if (parentNode == null)
{
return DirNode;
}
else
{
parentNode.ChildNodes.Add(DirNode);
return parentNode;
}
}
}
ASP Kode:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="treeview-new.aspx.cs" Inherits="NewFAQ_Howtos_treeview_new" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Panel ID="pnl" runat="server" > </asp:Panel>
</div>
</form>
</body>
</html>
Håber der er nogen der kan fortælle mig hvor jeg skal rette koden? :-)
Mvh Jacob