Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 268779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:44:07+00:00 2026-05-11T23:44:07+00:00

I am trying to set up a page that will allow the user to

  • 0

I am trying to set up a page that will allow the user to browse a file directory on the Web server.

The aim is to allow users to drop files within a given directory structure and the code will create the tree view based off the directory.

When setting the Nodes Navigate URL it maps to the C:\Staging\Files which obvioulsy does not work on the web. I would need to map to http://webaddress/staging/files etc

Here is the offending code

    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load


    If Not Page.IsPostBack Then
        '
        Dim rootDir As New DirectoryInfo("C:\Staging\")
        ' Enter the RecurseNodes function to recursively walk the directory tree. 
        Dim RootNode As TreeNode = RecurseNodes(rootDir)
        ' Add this Node hierarchy to the TreeNode control. 
        Treeview1.Nodes.Add(RootNode)
    End If
End Sub

Private Function RecurseNodes(ByVal thisDir As DirectoryInfo) As TreeNode


    Dim thisDirNode As New TreeNode(thisDir.Name, Nothing)
    ' Get all the subdirectories in this Directory. 
    Dim subDirs As DirectoryInfo() = thisDir.GetDirectories()
    For Each subDir As DirectoryInfo In subDirs
        thisDirNode.ChildNodes.Add(RecurseNodes(subDir))
    Next
    ' Now get the files in this Directory. 
    Dim files As FileInfo() = thisDir.GetFiles()
    For Each file As FileInfo In files
        Dim thisFileNode As New TreeNode(file.Name, Nothing)
        **thisFileNode.NavigateUrl = file.FullName**
        thisDirNode.ChildNodes.Add(thisFileNode)
    Next
    Return thisDirNode
End Function
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T23:44:07+00:00Added an answer on May 11, 2026 at 11:44 pm

    I think you should take the reverse approach. Rather than getting contents of a physical path on disk, try using Server.MapPath to grab contents of a virtual path combine it with a base URL:

    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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to set up a page that will allow users to download files
I am trying to set up a web page where trusted users can upload
I'm trying to set a page that displays the visitor's IP. All the methods
I am trying to set up a page on a wordpress site that displays
I am trying to set up so that my default page http://demo.liginsurance.com/ goes to
I'm trying to set up an html form that allows the user to select
For while I have been trying to set the Page Scaling of Excel page
I'm trying to set my default page to Index.html on an ASP.NET site running
im trying to set the height of two divs on my page, because my
I have been trying to set the scroll of my page to a certain

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.