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 7501783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:39:10+00:00 2026-05-29T20:39:10+00:00

I want to list files on a treeview and if I click on a

  • 0

I want to list files on a treeview and if I click on a treenode (a file), that file will be downloaded:

<asp:TreeView Id="MyTree" 
                      PathSeparator = "|"
                      OnTreeNodePopulate="PopulateNode"
                      ExpandDepth="0"
                      runat="server" ImageSet="XPDirectoryListing" NodeIndent="15">

            <SelectedNodeStyle BackColor="#B5B5B5"></SelectedNodeStyle>
            <NodeStyle VerticalPadding="2" Font-Names="Tahoma" Font-Size="8pt" HorizontalPadding="2" ForeColor="#000000"></NodeStyle>
            <HoverNodeStyle Font-Underline="True" ForeColor="#6666AA"></HoverNodeStyle>

            <Nodes>
                <asp:TreeNode Text="Demos" PopulateOnDemand="True" Value="Demos" />
            </Nodes>

        </asp:TreeView>

And code-behind:

public partial class DirectoryListing : System.Web.UI.Page
{
    protected void PopulateNode(Object source, TreeNodeEventArgs e)
    {
        TreeNode node = e.Node;

        if (e.Node.Value == "Demos")
        {
            e.Node.Value = Server.MapPath("~/");
        }

        String[] dirs = Directory.GetDirectories(node.Value);

        // Enumerate directories
        foreach (String dir in dirs)
        {
            TreeNode newNode = new TreeNode(Path.GetFileName(dir), dir);

            if (Directory.GetFiles(dir).Length > 0 || Directory.GetDirectories(dir).Length > 0)
            {
                newNode.PopulateOnDemand = true;
            }

            node.ChildNodes.Add(newNode);
        }

        // Enumerate files
        String[] files = Directory.GetFiles(node.Value);

        foreach (String file in files)
        {
            TreeNode newNode = new TreeNode(Path.GetFileName(file), file);
            node.ChildNodes.Add(newNode);
        }
    }
}

How can I change it such a way that I click on a treenode, the file at the treenode will be downloaded.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 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-29T20:39:12+00:00Added an answer on May 29, 2026 at 8:39 pm

    If your application is an intranet app, then this might work:

    TreeNode newNode = new TreeNode(Path.GetFileName(file), file);
                newNode.SelectAction = TreeNodeSelectAction.Select;
                newNode.NavigateUrl = Path.GetFullPath(file);
                node.ChildNodes.Add(newNode);
    

    If it’s not an intranet app you could hook on to the selectedNodeChanged event on the treeview and use a file streamer to stream the file to the client. But you most likely have to specify the MIME type of the file depending on what files you plan to send.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to list files from my disk to a BlockingQueue and threads will
I only want a list of files that have been added (not ones that
i want to list files from dev end at tty bettwen 15 and 24...should
I want to list all files in a directory Using PyroCMS. Using the Files
I want to list all files on an FTP server using PHP. According to
I want to list all .xml files in a dir and its subdir. I
I want to generate a list of files where the name consists of ${filename}.${date}
I want to get a list of files and then read the results into
I want to list a names of the files and put them into String
I want to add list of mp3 files to iTunes via a applescript. The

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.