刚刚创建了一个小的应用程序,这似乎工作。
这需要一个文本框与非UNC值,并将其转换,则设置了一个标签
请记住,包括下面的命名空间,如果你还没有准备好;
Imports System.Text
Imports System.IO
这是做所有工作的方法;
Private Function GetUNCPath(ByVal sFilePath As String) As String
Dim allDrives() As DriveInfo = DriveInfo.GetDrives()
Dim d As DriveInfo
Dim DriveType, Ctr As Integer
Dim DriveLtr, UNCName As String
Dim StrBldr As New StringBuilder
If sFilePath.StartsWith("\\") Then Return sFilePath
UNCName = Space(160)
GetUNCPath = ""
DriveLtr = sFilePath.Substring(0, 3)
For Each d In allDrives
If d.Name = DriveLtr Then
DriveType = d.DriveType
Exit For
End If
Next
If DriveType = 4 Then
Ctr = WNetGetConnection(sFilePath.Substring(0, 2), UNCName, UNCName.Length)
If Ctr = 0 Then
UNCName = UNCName.Trim
For Ctr = 0 To UNCName.Length - 1
Dim SingleChar As Char = UNCName(Ctr)
Dim asciiValue As Integer = Asc(SingleChar)
If asciiValue > 0 Then
StrBldr.Append(SingleChar)
Else
Exit For
End If
Next
StrBldr.Append(sFilePath.Substring(2))
GetUNCPath = StrBldr.ToString
Else
MsgBox("Cannot Retrieve UNC path" & vbCrLf & "Must Use Mapped Drive of SQLServer", MsgBoxStyle.Critical)
End If
Else
MsgBox("Cannot Use Local Drive" & vbCrLf & "Must Use Mapped Drive of SQLServer", MsgBoxStyle.Critical)
End If
End Function
声明此功能;
Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" (ByVal lpszLocalName As String, _
ByVal lpszRemoteName As String, ByRef cbRemoteName As Integer) As Integer
从按钮点击调用代码;
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim RealFileName As String = GetUNCPath(txtFileName.Text)
lblUNC.Text = RealFileName
End Sub
希望这会有所帮助。
我认为必须将驱动器映射到使用上述code.As我已经讲过了我们的车程仅适用于共享未映射 – 2013-04-24 09:11:20
你甚至尝试上面的代码? – Jacooobley 2013-04-24 09:29:12
是刚刚tried..cannot使用本地驱动器,必须使用SQL Server错误的映射驱动器来 – 2013-04-24 09:36:03