2013-12-20 1 views
-1
나는 버튼 그러나 나는 단지이 가능하며, 그것이 내가 그 폴더를 편집 할 수 설정 만에 사용자에 대한 파일 경로에 열려 클릭에서 파일 대화 상자를 열려면

?Visual Basic에서 파일을 여는 대화

+0

을 닫지 않고 FileOk 이벤트를 사용하여 다른 디렉토리에있는 파일을 선택하면

당신은 대화 상자를 열기 전에 InitialDirectory 속성을 설정 및 확인할 수 있습니다 특정 경로를 지정하지만 해당 폴더에 잠겨 있어야합니다. – user3118124

+0

Dim fd As OpenFileDialog = 새 OpenFileDialog fd.InitialDirectory = "파일 경로" – user3118124

+0

@ FileDown 이벤트를 사용하여 @Steve 응답을 따르십시오. – equisde

답변

1

아니, 그/그녀가 갈 권한이있는 경우 다른 디렉토리로 이동하는 사용자를 차단하는 방법이 없습니다. OpenFileDialog은 현재 디렉토리를 차단할 인프라를 제공하지 않습니다.

FolderBrowserDialog 클래스가있다, 그러나 이것은 폴더를 선택에만 사용되며 파일을 선택하지. 사용자가 내가 그것을 열 얻을 수 있었다 지금까지 대화

Dim openFileDialog1 As New OpenFileDialog() 
openFileDialog1.InitialDirectory = "c:\temp\testpath" 
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" 
openFileDialog1.FilterIndex = 2 
openFileDialog1.RestoreDirectory = True 
....... 


Private Sub openFileDialog1_FileOk(ByVal sender As Object, _ 
     ByVal e As System.ComponentModel.CancelEventArgs) _ 
     Handles OpenFileDialog1.FileOk 

    Dim ofd = CType(sender, OpenFileDialog) 
    if ofd.Filename <> string.Empty Then 
     if Path.GetDirectoryName(ofd.Filename).ToLower() <> "c:\temp\testpath" Then 
      MessageBox.Show("Please choose a file only from C:\TEMP\TESTPATH folder") 
      ' Just cancel the OK, not found any way to reposition the dialog on the correct folder' 
      e.Cancel = true 
     Endif 
    End If 
End Sub