Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9
This is the forum to discuss the Wrox book Professional ASP.NET 2.0 Special Edition by Bill Evjen, Scott Hanselman, Devin Rader, Farhan Muhammad, Srinivasa Sivakumar; ISBN: 9780470041789
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 14th, 2006, 01:20 AM
Authorized User
 
Join Date: Feb 2006
Location: Houston, Texas, USA.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Listing 22-6

Hello - I have tried to modify this sample (displaying files & folders in a TreeView & GridView) to limit it to folders & files down a specific path, but on every node click, it adds on an additional, duplicated hierarchy.

Could you please show me how I could start this sample on a specific folder (say, "C:\Websites\MyWebsite\ClientFiles\Client1234\ "), and have it work down from there?

Thanks very much

Mark

  #2 (permalink)  
Old March 22nd, 2006, 06:42 PM
Wrox Author
 
Join Date: Dec 2005
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Instead of looping through the drives in the Page_Load event, I think if you modify where I call the LoadDirectories method you could do it:

Inside of Page_Load:

Dim node as TreeNode = New TreeNode()
node.Value = "Your Root"
LoadDirectories(node,"C:\Foo\bar\")
Me.TreeView1.Nodes.Add(node)

Devin
  #3 (permalink)  
Old March 26th, 2006, 01:29 PM
Registered User
 
Join Date: Sep 2003
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your reply

Yes, I finally figured that out. Also, I had a problem with it loading another root node into the TreeView every time I clicked on a folder. Here's what I wound up with (such as it is; I'm new at this):

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

        If Not Page.IsPostBack Then
            Dim node As TreeNode = New TreeNode()
            node.Value = "C:\Websites\WebProject\ClientArea\PDFs\" & Session("strAcctNo") & "\"
            node.Text = "Client " & Session("strAcctNo")
            LoadDirectories(node, "C:\Websites\WebProject\ClientArea\PDFs\" & Session("strAcctNo") & "\")
            Me.TreeView1.Nodes.Add(node)
        End If
    End Sub

I had another problem trying to make a HyperLinkField to link to a given file; when I set it to use the FullPath property, it stopped appearing as a link. Something about it not being spec'd as a relative path, I guess. I got some help on that one (thanks to "aki4u" over at ExpertsExchange):

    Protected Sub TreeView1_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.SelectedNodeChanged

        Dim directory As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(Me.TreeView1.SelectedNode. Value)

        'Me.GridView1.DataSource = directory.GetFiles()
        Me.GridView1.DataSource = GetFilesDataTable(directory.GetFiles())

        Me.GridView1.DataBind()

    End Sub

-----------------------------------------------------------------------
    Private Function GetFilesDataTable(ByVal arrFi As IO.FileInfo()) As Data.DataTable

        Dim dt As Data.DataTable = New Data.DataTable()

        dt.Columns.Add("Name")
        dt.Columns.Add("Length")
        dt.Columns.Add("LastWriteTime")
        dt.Columns.Add("PathToTheFile")

        'For Each fi As FileInfo In arrFi
        Dim cnt As Integer = 0

        For cnt = 0 To arrFi.Length - 1
            dt.Rows.Add(dt.NewRow())
            dt.Rows(cnt)(0) = arrFi(cnt).Name
            dt.Rows(cnt)(1) = arrFi(cnt).Length
            dt.Rows(cnt)(2) = arrFi(cnt).LastWriteTime
            'dt.Rows(cnt)(3) = arrFi(cnt).FullName
            'dt.Rows(cnt)(3) = "\WebProject\ClientArea\" & (Client#) & "\" & (Year()) & "\" & arrFi(cnt).Name
            dt.Rows(cnt)(3) = arrFi(cnt).FullName.Substring(11)
        Next

        Return dt

    End Function

-----------------------------------------------------------------------
Then on the GridView:

            <asp:HyperLinkField
                DataNavigateUrlFields="PathToTheFile"
                DataNavigateUrlFormatString="{0}"
                DataTextField="Name"
                HeaderText="File Name" />




 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Listing 8-10 and Listing 8-16. Asp.Net BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 1 February 6th, 2008 01:11 PM
Binding Navigator in Ch 22 Nick Y BOOK: Ivor Horton's Beginning Visual C++ 2005 0 August 4th, 2006 01:39 PM
addhandler catch 22 roog ASP.NET 1.0 and 1.1 Professional 2 February 20th, 2006 01:01 PM
string formatter = "{0,22} {1}"; //what it mean? fukchai2000 C# 1 January 6th, 2006 08:36 AM
Issues about PerformanceCounter (Chapter 22) newmike BOOK: Professional C#, 2nd and 3rd Editions 0 June 15th, 2004 10:10 PM



All times are GMT -4. The time now is 09:52 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.