Question about listing directories from client machine Kenya
  • 12 years ago

    Hi to all. I've been trying to find a way of resolving a problem I have and I can't quite figure it out how to do it. Sad

    I would like to achieve the following: I want to be able to list the directories (and subdirectories) of the hard drive of an user local machine, when he access a web page, displayed in a treeview, like a kind of XP File Explorer.

    Is this possible, at all? If it is, how can I achieve this? Can I make this using "regular", or "hell no!"? I'm asking this because I really can't seem to understand how I could list the folders of the client hardrive. For example, I can't run a command like this

    Dim drives As String() = Directory.GetLogicalDrives()

    in a way that it lists the drives of the PC of the client that is accessing the webpage, can I?

    If this can't be done by "regular" code, how could I do it? ActiveX? Ajax? I haven't worked with any of these technologies so I'm really just wondering here...

    At this point I don't even care if I can already put the directories in a treeview or not... I would just be happy to know a way to just print the list of directories.

    I would appreciate if somebody could please direct me to a direction, an article or something that would enlighten me on what and how to do this.
    Thanks in advance.


  • 12 years ago

    I can only give a generic solution that works for me, and I think you are on the right lines already. The following code will list all files in the MyPictures folder, but not the subdirectories. Change the second parameter in the GetFiles method to search all subdirectories also. I think you can create a general routine that will list all directories on the client machine, although this is highly inadvisable. It is best to be specific with the directory being accessed on a webclient or let the client browse to the necessary directory.

    It might be better if you limit your online directories to the SpecialDirctories used with the My keyword.

    Private path As String = My.Computer.FileSystem.SpecialDirectories.MyPictures & "\Wedding"
        Protected Sub btnFillList_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFillList.Click
            For Each foundFile As String In My.Computer.FileSystem.GetFiles(path, FileIO.SearchOption.SearchTopLevelOnly)
        End Sub
  • 12 years ago

    Hi there,

     I think D'Scouser's code shows existing files on the server. You must create an ActiveX for that.

  • 12 years ago

    You're right Mehdi, but the kid's on the right tracks using the Directory object, and just change the GetFiles method for GetDirectories

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“I invented the term Object-Oriented, and I can tell you I did not have C++ in mind.” - Alan Kay