As others pointed out, you can't launch a windows file explorer on the "client" side computer. As pointed out, when you launch a windows file explorer, it launches on the server side - not the users computer (running a browser).
However, you can certainly build your own "file" page in asp.net, and "display" the files in a gridview, or listview.
And, you can even say drop in a treeview, and "fake" a file like explorer.
So, say we drop in a treeview control into our page. So, we have this markup (I used the "auto format", so it will setup the icons automatic for you.
So, this markup:
<h3 id="fileHead" runat="server"></h3>
<asp:TreeView ID="TreeView1" runat="server" ImageSet="XPFileExplorer"
NodeIndent="15" OnTreeNodeExpanded="TreeView1_TreeNodeExpanded1" >
<HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" />
<NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="Black"
HorizontalPadding="2px" NodeSpacing="0px" VerticalPadding="2px" />
<ParentNodeStyle Font-Bold="False" />
<SelectedNodeStyle BackColor="#B5B5B5" Font-Underline="False"
HorizontalPadding="0px" VerticalPadding="0px" />
</asp:TreeView>
So, I just dragged + dropped in a treeview.
And the code is quite easy - and it not even recursive (it does not help for this type of problem).
So, my code looks like this:
Dim sRoot As String = "c:\SERVER01"
Public Class MyFolder
Public MyFiles As FileInfo()
Public MyFolders As DirectoryInfo()
End Class
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
fileHead.InnerText = sRoot
Dim MyFiles As MyFolder = GetFiles(sRoot)
LoadTreeFiles(sRoot, MyFiles, "", Nothing)
End If
End Sub
So, above is the page load.
And then the additional code on that page is this:
Public Function GetFiles(sRootFolder) As MyFolder
Dim MyDir As New DirectoryInfo(sRootFolder)
Dim cMyFolder As New MyFolder
cMyFolder.MyFolders = MyDir.GetDirectories("*.*", SearchOption.TopDirectoryOnly)
cMyFolder.MyFiles = MyDir.GetFiles("*.*", SearchOption.TopDirectoryOnly)
Return cMyFolder
End Function
Sub LoadTreeFiles(fRootL As String,
lParent As MyFolder,
sParentID As String,
tTreeNode As TreeNode)
' add folders if any
For Each sFolder As DirectoryInfo In lParent.MyFolders
Dim child As New TreeNode
child.Text = sFolder.Name
child.Value = sFolder.FullName
child.Expanded = False
child.PopulateOnDemand = True
child.ShowCheckBox = False
If sParentID = "" Then
TreeView1.Nodes.Add(child)
Else
tTreeNode.ChildNodes.Add(child)
End If
Next
' now any files
For Each sFile As FileInfo In lParent.MyFiles
Dim child As New TreeNode
child.Text = sFile.Name
child.Value = sFile.FullName
child.Expanded = False
child.ShowCheckBox = True
child.PopulateOnDemand = False
If sParentID = "" Then
TreeView1.Nodes.Add(child)
Else
tTreeNode.ChildNodes.Add(child)
End If
Next
End Sub
Protected Sub TreeView1_TreeNodeExpanded1(sender As Object, e As TreeNodeEventArgs) Handles TreeView1.TreeNodeExpanded
Dim child As TreeNode = e.Node
Dim dtChild As MyFolder = GetFiles(child.Value)
LoadTreeFiles(child.Value, dtChild, child.Text, child)
End Sub
Now, about is the "max" amount of code I would dare post here. Not too much, and apologies if this posting has too much code.
So, now, the result looks like this:
