Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think you should take the reverse approach. Rather than getting contents of a physical path on disk, try using <code>Server.MapPath</code> to grab contents of a virtual path combine it with a base URL:</p> <pre><code>Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then Dim RootNode As TreeNode = RecurseNodes("~/files") TreeView1.Nodes.Add(RootNode) End If End Sub Private Overloads Function RecurseNodes(ByVal virtualPath As String) As TreeNode If Not VirtualPathUtility.IsAbsolute(virtualPath) Then virtualPath = VirtualPathUtility.ToAbsolute(virtualPath) virtualPath = VirtualPathUtility.RemoveTrailingSlash(virtualPath) Dim baseUrl As String = Request.Url.GetLeftPart(UriPartial.Authority) + virtualPath Return RecurseNodes(New DirectoryInfo(Server.MapPath(virtualPath)), baseUrl) End Function Private Overloads Function RecurseNodes(ByVal thisDir As DirectoryInfo, ByVal baseUrl As String) As TreeNode Dim thisDirNode As New TreeNode(thisDir.Name, Nothing) Dim subDirs As DirectoryInfo() = thisDir.GetDirectories() For Each subDir As DirectoryInfo In subDirs thisDirNode.ChildNodes.Add(RecurseNodes(subDir, baseUrl + subDir.Name + "/")) Next Dim files As FileInfo() = thisDir.GetFiles() For Each file As FileInfo In files Dim thisFileNode As New TreeNode(file.Name, Nothing) thisFileNode.NavigateUrl = baseUrl + file.Name thisDirNode.ChildNodes.Add(thisFileNode) Next Return thisDirNode End Function </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload