2016-03-28 55 views
2

參考:Ookii.Dialogs.Wpf.VistaOpenFileDialogVistaOpenFileDialog不正確的初始目錄開始

我正在嘗試設置Ookii的VistaOpenFileDialog初始目錄是這樣的:

VistaOpenFileDialog vfb = new VistaOpenFileDialog(); 
     vfb.Multiselect = true; 
     vfb.Title = "pouet"; 
     vfb.RestoreDirectory = false; 
     vfb.InitialDirectory = @"C:\Users\"; 
     if (vfb.ShowDialog() ?? false) 
     { 
      this.Dispatcher.Invoke(DispatcherPriority.Send, new Action(delegate 
      { 
       for (var i = 0; i < vfb.FileNames.Length; i++) 
       { 
        FileDisplay.Add(vfb.FileNames[i]);      
       } 
      })); 
     } 
    } 

    private void AddFiles_Click(object sender, RoutedEventArgs e) 
    { 
     t = new Thread(new ThreadStart(AddFileDialog)); 
     t.SetApartmentState(ApartmentState.STA); 
     t.Start(); 
    } 

但無論我儘量不工作,對話從不首先由初始目錄打開,也不從初始目錄重新打開。我仍然可以選擇文件夾沒有問題。

我已經嘗試以下操作(測試):

vfb.InitialDirectory = @"C:\Users\"; 
vfb.InitialDirectory = "C:\\Users\\"; 
vfb.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop).ToString(); 

也試過restoredirectory真的還是假的不會改變任何東西。

回答

1

我剛剛遇到了這個問題。我不知道爲什麼它不是這樣工作的,但我發現如果將FileName屬性設置爲該文件夾,它將在指定路徑中打開:

VistaOpenFileDialog dialog = new VistaOpenFileDialog(); 
// To show the contents of "C:\", i.e. the parent of "Users": 
dialog.FileName = @"C:\Users" 
// To show the contents of the "Users" directory: 
dialog.FileName = @"C:\Users\"