tags:

views:

306

answers:

3

I have a header table that has a list of web pages in it. Each record has a page URL field which I am looking to parse out into a hierarchy (TreeView). I am not sure of the best way to go about it and I am having a problem getting it to work.

Here's an example of URLS:

/file1.aspx
/file2.aspx
/aFolder/file.aspx
/aFolder/file2.aspx
/bfolder/file.aspx
/bFolder/cFolder/file.aspx

I want to put this type of a list into a file explorer style treeview that you can expand the folders and then select the file at the end.

Something like

--Root
  |
  +-aFolder
  |   - aFolderFile1.aspx
  |   - aFolderFile2.aspx
  +-bFolder
      +-cFolder
      |    -cFolderFile1.aspx
      -bFolderFile1.aspx

The real data obviously has more sub folders and files in each.

What I am looking for is some code, be it .NET or SQL to parse my strings. I have tried to use some SQL that used WITH and UNION ALL but I just can't get it to work for me.

In order to bind it to a TreeView, the data source needs to have a parent field in order to relate the nodes. So, for example the parent for the file cFolderFile1.aspx is cFolder and the cFolder has a parent of bFolder, and so on....

Hopefully I've included enough information. If not, please let me know and I will edit the post.

A: 

I'm pretty sure you can bind a SqlDataSource directly to the .NET treeview. Here's two forums that cover that:

Building a Treeview From a SqlDataSource

Dynamic treeview

Mike Robinson
Thanks for the links. I don't think those will work though because they mainly deal with physical folders but mine are listed in a DB. In this case, I don't have a parentID/childID that I can use to relate the records - just the full URL in a string.
hacker
A: 

Thanks for the suggestions everyone. None of the links seemed to be exactly what I was looking for so I ended up putting something together.

There is a bunch of code, but in general, I read the list of URLs into a Generic List with some extra properties and used some regex statements to parse out the path.

Because the list of URLS did not have any sort of parent ID / child ID, I used the FIND function and got the pieces I needed.

hacker