2012-10-02 1296 views
0

我構建了一個樹狀結構來顯示本地機器上的遠程機器的目錄。 它適用於在本地機器上顯示目錄,但不適用於遠程機器。在樹狀視圖中構建遠程機器(LAN)的目錄結構

下面是代碼,會很高興,如果有人能告訴我如何使這項工作與遠程機

Imports System.IO 
Imports System.Collections.Generic 
Imports System.ComponentModel 
Imports System.Windows.Forms 
Imports System.Linq 
Imports System.Drawing 
Imports System.Data 

Public Class GPSTestAuto 
Private mRootPath() As String = Directory.GetFileSystemEntries("\\192.168.0.35\Test Drive\ULTS\") 
    Property RootPath As String 
     Get 
      Return mRootPath(0) 
     End Get 
     Set(value As String) 
      mRootPath(0) = value 
     End Set 
    End Property 
    Private Sub GPSTestAuto_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load 

     Dim mRootNode As New TreeNode 
     mRootNode.Text = RootPath 
     mRootNode.Tag = RootPath 

     mRootNode.Nodes.Add("*DUMMY*") 
     TreeView1.Nodes.Add(mRootNode) 

    End Sub 
    Private Sub TreeView1_BeforeCollapse(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles TreeView1.BeforeCollapse 
     ' clear the node that is being collapsed 
     e.Node.Nodes.Clear() 
     ' add a dummy TreeNode to the node being collapsed so it is expandable 
     e.Node.Nodes.Add("*DUMMY*") 
    End Sub 

    Private Sub TreeView1_BeforeExpand(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles TreeView1.BeforeExpand 
     ' clear the expanding node so we can re-populate it, or else we end up with duplicate nodes 
     e.Node.Nodes.Clear() 
     ' get the directory representing this node 
     Dim mNodeDirectory As IO.DirectoryInfo 
     mNodeDirectory = New IO.DirectoryInfo(e.Node.Tag.ToString) 
     ' add each subdirectory from the file system to the expanding node as a child node 
     For Each mDirectory As IO.DirectoryInfo In mNodeDirectory.GetDirectories 
      ' declare a child TreeNode for the next subdirectory 
      Dim mDirectoryNode As New TreeNode 
      ' store the full path to this directory in the child TreeNode's Tag property 
      mDirectoryNode.Tag = mDirectory.FullName 
      ' set the child TreeNodes's display text 
      mDirectoryNode.Text = mDirectory.Name 
      ' add a dummy TreeNode to this child TreeNode to make it expandable 
      mDirectoryNode.Nodes.Add("*DUMMY*") 
      ' add this child TreeNode to the expanding TreeNode 
      e.Node.Nodes.Add(mDirectoryNode) 
     Next 
    End Sub 
End Class 

回答

1

我認爲你的問題是從前段時間有關mine,是由於安全限制。您需要在遠程計算機上創建相同的用戶帳戶,並且如果代碼位於Web應用程序中,則必須將其包裝到使用本地帳戶的WindowsImpersonationContext中。我得到了這個工作,但它比它需要更復雜。

this question的回答對我來說是最有幫助的一個解決方案。