2012-09-08 11 views
1

많은 컴퓨터 드라이브가있는 컴퓨터 네트워크에서 100 개의 파일을 참조하는 문서 인덱싱 시스템을 작성 중입니다. 새 드라이브가 추가되거나 네트워크에서 드라이브가 제거되면 드라이브 문자가 다시 할당됩니다. 따라서 드라이브 문자를 사용하는 특정 파일 경로는 해당 드라이브 문자가 다시 할당되면 의미가 없어 질 수 있습니다. 이 문제를 피하기 위해 대신 UNC (범용 명명 규칙) 경로 이름을 사용하려고합니다.Visual Studio 2010을 사용한 UNC 변환

아래 코드는 Excel 2007에서 실행될 때 드라이브 문자를 해당 UNC로 변환합니다. 그러나 Visual Studio 2010에서 응용 프로그램을 작성했지만 불행히도 아래 코드는 Visual Studio에서 작동하지 않는 것 같습니다. 실행될 때 오류가보고되지 않지만 UNC를 반환하지 않습니다. '참조'에 문제가있을 수 있습니다.

Imports System 
Imports System.Management 
Module Module1 

' 32-bit Function version. 
' Enter this declaration on a single line. 
Declare Function WNetGetConnection Lib "MPR.DLL" Alias _ 
    "WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal _ 
    lpszRemoteName As String, ByVal lSize As Long) As Long 

Dim lpszRemoteName As String 
Dim lSize As Long 

' Use for the return value of WNetGetConnection() API. 
Const NO_ERROR As Long = 0 

' The size used for the string buffer. Adjust this if you 
' need a larger buffer. 
Const lBUFFER_SIZE As Long = 255 


Sub GetNetPath() 
    Dim DriveLetter, lpszLocalName As String 
    Dim cbRemoteName As Long 
    Dim lStatus& 


    ' Prompt the user to type the mapped drive letter. 
    DriveLetter = UCase(InputBox("Enter Drive Letter of Your Network" & _ 
     "Connection." & Chr(10) & "i.e. F (do not enter a colon)")) 

    ' Add a colon to the drive letter entered. 
    lpszLocalName = DriveLetter & ":" 

    ' Specifies the size in characters of the buffer. 


    ' Prepare a string variable by padding spaces. 
    lpszRemoteName = lpszRemoteName & Space(lBUFFER_SIZE) 
    cbRemoteName = Len(lpszRemoteName) 
    ' Return the UNC path (\\Server\Share). 
    lStatus& = WNetGetConnection(lpszLocalName, lpszRemoteName, _ 
     cbRemoteName) 

    ' Verify that the WNetGetConnection() succeeded. WNetGetConnection() 
    ' returns 0 (NO_ERROR) if it successfully retrieves the UNC path. 
    If lStatus& = NO_ERROR Then 

     ' Display the UNC path. 
     MsgBox(Left$(lpszRemoteName, cbRemoteName)) 

    Else 
     ' Unable to obtain the UNC path. 
     MsgBox("Unable to obtain the UNC path.") 
    End If 

End Sub 


End Module 

감사의 말씀을드립니다. 대단히 고마워요

답변

0

편도는 입니다. string strUncpath = "file : \"; thenjust 앞에 추가이 경로에

strUncpath + 이제까지 당신의 경로 또는 파일 붙일이 밖으로 확장 메서드를 만들 수있는 :

를 요이하기 위해 \를