剛剛創建了一個小的應用程序,這似乎工作。
這需要一個文本框與非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