473,786 Members | 2,420 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TreeView ASP.NET

91 New Member
Hi I am pretty new to ASP.NET. I have inserted a Treeview control in my page, which display directory information & all the different files contained in it in a DataList infront of it. My question is how can I make users to OPEN or DOWNLOAD these files. rightnow throuh this code only the name of the file is displayed in DataList, I want them to open in their respective programs & be downloaded as well. Thanks.

PictureTree is my TREEVIEW &
PicturesInFolde r is my DATALIST which display files in that folder

Expand|Select|Wrap|Line Numbers
  1. Imports System.IO
  2. Partial Class folder
  3.     Inherits System.Web.UI.Page
  4.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  5.         'On the first page visit, populate the photo tree and select the root node
  6.         If Not Page.IsPostBack Then
  7.             PopulateTree()
  8.             PictureTree.Nodes(0).Select()
  9.             PictureTree_SelectedNodeChanged(PictureTree, EventArgs.Empty)
  10.         End If
  11.     End Sub
  12.     Private Const VirtualImageRoot = "~/Data/"
  13.     Private Sub PopulateTree()
  14.         'Populate the tree based on the subfolders of the specified VirtualImageRoot
  15.         Dim rootFolder As New DirectoryInfo(Server.MapPath(VirtualImageRoot))
  16.         Dim root As TreeNode = AddNodeAndDescendents(rootFolder, Nothing)
  17.         'Add the root to the TreeView
  18.         PictureTree.Nodes.Add(root)
  19.     End Sub
  20.     Private Function AddNodeAndDescendents(ByVal folder As DirectoryInfo, ByVal parentNode As TreeNode) As TreeNode
  21.         'Add the TreeNode, displaying the folder's name and storing the full path to the folder as the value...
  22.         Dim virtualFolderPath As String
  23.         If parentNode Is Nothing Then
  24.             virtualFolderPath = VirtualImageRoot
  25.         Else
  26.             virtualFolderPath = parentNode.Value & folder.Name & "/"
  27.         End If
  28.         Dim node As New TreeNode(folder.Name, virtualFolderPath)
  29.         'Recurse through this folder's subfolders
  30.         Dim subFolders As DirectoryInfo() = folder.GetDirectories()
  31.         For Each subFolder As DirectoryInfo In subFolders
  32.             Dim child As TreeNode = AddNodeAndDescendents(subFolder, node)
  33.             node.ChildNodes.Add(child)
  34.         Next
  35.         Return node     'Return the new TreeNode
  36.     End Function
  37.     Protected Sub PictureTree_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureTree.SelectedNodeChanged
  38.         'Refresh the DataList whenever a new node is selected
  39.         DisplayPicturesInFolder(PictureTree.SelectedValue)
  40.     End Sub
  41.     Private Sub DisplayPicturesInFolder(ByVal virtualFolderPath As String)
  42.         'Security check: make sure folderPath starts with VirtualImageRoot and doesn't include any ".."
  43.         If Not virtualFolderPath.StartsWith(VirtualImageRoot) OrElse virtualFolderPath.IndexOf("..") >= 0 Then
  44.             Throw New ApplicationException("Attempting to view a folder outside of your root folder!")
  45.         End If
  46.         'Get information about the files in the specified folder
  47.         Dim folder As New DirectoryInfo(Server.MapPath(virtualFolderPath))
  48.         Dim fileList As FileInfo() = folder.GetFiles()
  49.  
  50.         PicturesInFolder.DataSource = fileList
  51.         PicturesInFolder.DataBind()
  52.         'subNode.NavigateUrl = Server.MapPath(fi.Name.ToString())
  53.         'If there are no pictures in the folder, display the NoPicturesInFolderMessage Label
  54.         PicturesInFolder.Visible = PicturesInFolder.Items.Count > 0
  55.         NoPicturesInFolderMessage.Visible = Not PicturesInFolder.Visible
  56.     End Sub
  57.  
Jan 13 '09 #1
1 2565
Frinavale
9,735 Recognized Expert Moderator Expert
You need to give the user a way to select the file they want to view/download.
Add a Select Button (or CheckBox column if you want to let them download more than one file) to your GridView. When the user clicks the Select button, display a link to let them download the file selected.
Jan 20 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

42
11557
by: lauren quantrell | last post by:
So many postings on not to use the treeview control, but nothing recently. Is it safe to swim there yet with Access 2000-Access 2003?
5
19891
by: SoKool | last post by:
Can anyone point me to a site where I can get a free treeview control to use in ASP .NET or any tutorial that can help me build my own treeview control. I intend to use a treeview to generate a dynamic menu by collating data from a Sql Server Table. Many thanks.
1
6681
by: paradox | last post by:
I want to have a TreeView that shows an image on some items, but not all. Basically, if a certain condition is true, a caution icon is placed next to the treeview item. The problem is that, by adding a ImageList to the TreeView, the ImageIndex property of the items in the TreeView defaults to 0. I could put a blank icon in the ImageList and make it the 0 index image, however, this makes an ugly space. Would I have to create my own...
3
2834
by: Peter | last post by:
Hello, We are inserting a side menu to our application using a class that is writing HTML on all our pages. This is a part of the code as an example: writer.Write(" <table WIDTH=""100%"" BORDER=""0"" CELLSPACING=""0"" CELLPADDING=""0"" ID=""Table1""> " & vbNewLine) writer.Write(" <tr>" & vbNewLine) writer.Write(" <td>" & vbNewLine)
6
4934
by: L.M | last post by:
Hello, I knew how to use the treeview under VB6. After migrating to .NET, well, I'm lost. I try to add a new node, either to the same level or as a child to a selected node in the treeview. However, either it only add it to the root level or it only add it on level below, doesn't matter what I select. And in some case, I just get an exception.
14
15100
by: Mr.D | last post by:
How do I save/load the contents of a Treeview to a file? I have found several good examples written i VB6, but not a single one for VB.NET. Please help. ---- Tim
3
3830
by: christof | last post by:
I've got a really easy problem, please help me: There are two pages in one I'm creating a TreeView like that: TreeView dbTree = new TreeView(); TreeNode dbTreeRoot = new TreeNode("Root"); dbTree.Nodes.Add(dbTreeRoot); .. ..
2
7500
by: Tymbow | last post by:
I'm building a web application that is analogous to the Windows XP file explorer in function. The left column contains a TreeView, and the right column a DataGrid populated by selecting TreeView nodes. The TreeView populates dynamically as there are a significant number of nodes. The DataGrid displays both the items and the nodes from the TreeView. Using the explorer analogy this means the TreeView shows folders, and the DataGrid folders...
1
693
by: kvicky | last post by:
I am trying to load child nodes to a TreeNode in a TreeView in a ASP.net web application. The Treeview with parent nodes are loaded on a Page_load while doing if( ! ISPostback ) and then in the Treeview event I am dynamically trying to load the child nodes to the exisisting TreeView. The problem is since the TreeView is being loaded on not a Postback, I am unable to refer to any node in the TreeView event. Can anybody tell me how to...
8
12776
by: Matt MacDonald | last post by:
Hi All, I have a form that displays hierarchical categories in a treeview. Ok so far so good. What I was to do is have users be able to select a node in the treeview as part of filling out the form. I only want to allow single selection, so using checkboxes is out of the question. It works as is, but it makes the form very cumbersome if every time that a user selects a node, the whole page has to reload. Is there a way to have a node...
0
9496
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10164
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8989
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3669
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.