在局域网中,如何读取指定IP已共享的文件夹中,子目录和文件呢???(有代码,帮瞧瞧吧。)
哪位朋友帮瞧一下如下代码,当读取本地化模板时,一切正常,当把MyPath改为局域网中指定的IP电脑共享的目录时,就无法读到模板了,局域网采用的是域管理方式。用后面的ConnectServer()也无法登入,用户和密码绝对正确的,不知如何解。我的目地就是想通过IP读取网络中某台电脑已共享的目录,子目录,及文件。不知大家有什么好的方法。十分感谢!!
'Dim MyPath As String = "\\192.168.0.201\Document\模板\"
Dim MyPath As String = "D:\bin\Document\模板\"
Dim MyDirectories As String()
=================================================================
'选定模板类型。
Private Sub 模_类型_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 模_类型.SelectedIndexChanged
ReadTemplateSort()
End Sub
=================================================================
'读取所选定的 模板目录列表 到 ListBox1_模板目录列表 控件。
Private Sub ReadTemplateSort()
Dim MySubPath As String = MyPath + Me.模_类型.SelectedItem + "\"
MyDirectories = Directory.GetDirectories(MySubPath)
Dim MySubDirectories As String
For Each MySubDirectories In MyDirectories
Me.ListBox1_模板目录列表.Items.Add(MySubDirectories.Remove(0, MySubPath.Length))
Next
End Sub
=====================================================
Imports System.Management
Imports System.Net
Imports System.IO
Private Sub ConnectServer(ByVal IPAdress As String, ByVal UserName As String, ByVal Password As String)
'通过IP,用户,密码连接服务器。
Try
Dim coption As New ConnectionOptions
coption.Username = CStr(Trim(UserName))
coption.Password = CStr(Trim(Password))
Dim scope As ManagementScope
scope = New ManagementScope("\\" & CStr(Trim(IPAdress)) & "\root\cimv2", coption)
scope.Connect()
If scope.IsConnected = True Then
MsgBox("连接成功!", MsgBoxStyle.OKOnly, "提示")
End If
'Catch ex As Exception
' MsgBox("无法连接服务器。", MsgBoxStyle.OKOnly, "提示")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub