locked
How can i get them using c#(asp.net) RRS feed

  • Question

  • User2061024676 posted
    <table class="style1">
                <tr>
                    <td>
                        <asp:ListBox ID="ListBox1" runat="server"></asp:ListBox>
                    </td>
                    <td>
                    <asp:TreeView ID="TreeView1" runat="server">
                    </asp:TreeView>
                        </td>
                    <td>
                        <asp:ListBox ID="ListBox2" runat="server"></asp:ListBox>
                    </td>
                </tr>
            </table>
    How to get all available local drive names in listbox1 and its folders in treeview and their file formats with extensions in listbox2??
    There are few sources where i can find them..but...they are available in VB. http://blogs.technet.com/b/heyscriptingguy/archive/2007/09/20/how-can-i-dynamically-show-available-drive-letters-in-a-list-box.aspx.
    Tuesday, January 17, 2012 11:09 AM

Answers

  • User3866881 posted

    Hello:)

    1)For getting all the drivers,you can try to use System.IO.Driver class:

     foreach (var item in DriveInfo.GetDrives())
                    {
                        Response.Write(item.Name);
                    }

    2)For getting all the files that belong to the specific driver,you can try to use System.IO.File class:

     foreach (var item in Directory.GetFiles("C:\\","*.*",SearchOption.TopDirectoryOnly))
                    {
                        Response.Write(item);
                    }

    3)Besides this,you can also have a look at this sample:http://www.codeproject.com/KB/aspnet/WebFileManager.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 18, 2012 8:42 PM

All replies

  • User455156504 posted

    Hi,

    if you want to get the local drives of a user: That's not possible in ASP.NET (because it's a server-side technology). You could Silverlight for that purpose.

    Tuesday, January 17, 2012 12:05 PM
  • User-1002157272 posted

    Yea, I mean there is ways to do this in ASP.NET via downloadable client apps or ActiveX controls but no client browser is going to just let your app have this kind of access without a fuss lol.

    Tuesday, January 17, 2012 5:35 PM
  • User3866881 posted

    Hello:)

    1)For getting all the drivers,you can try to use System.IO.Driver class:

     foreach (var item in DriveInfo.GetDrives())
                    {
                        Response.Write(item.Name);
                    }

    2)For getting all the files that belong to the specific driver,you can try to use System.IO.File class:

     foreach (var item in Directory.GetFiles("C:\\","*.*",SearchOption.TopDirectoryOnly))
                    {
                        Response.Write(item);
                    }

    3)Besides this,you can also have a look at this sample:http://www.codeproject.com/KB/aspnet/WebFileManager.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 18, 2012 8:42 PM
  • User455156504 posted

    If you want to do it on the server where your application is hosted go with the solution above.

    Thursday, January 19, 2012 4:29 AM
  • User2061024676 posted
     foreach (var item in Directory.GetFiles("C:\\","*.*",SearchOption.TopDirectoryOnly))
                    {
                        Response.Write(item);
                    }
    
    How could i get all the files in listbox when i select treeview's node
    Thursday, January 19, 2012 5:19 AM
  • User3866881 posted

    How could i get all the files in listbox when i select treeview's node

    Hello again:)

    I've shown you the codes above,and GetFiles is just what you want——Make sure that your treeview's node is a path (absolute or relative)。

    Reguards!

    Thursday, January 19, 2012 7:44 PM