0

I followed Joe's idea on how to use CommonOpenFileDialog to open a folder / file here

I've installed the package Microsoft.WindowsAPICodePack-Shell in my project and included this line as well: using Microsoft.WindowsAPICodePack.Dialogs;

The code:

private void Button_Click(object sender, RoutedEventArgs e)
{

     CommonOpenFileDialog dialog = new CommonOpenFileDialog();
     dialog.InitialDirectory = "C:\\Users";
     dialog.IsFolderPicker = true;
     dialog.Multiselect = true;

     if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
     {

         MessageBox.Show("You selected: " + dialog.FileName);
     }

}

However, there are some methods / attributes that I could not use. I screenshotted the errors I got: errors

Is there an updated documentation on how to use the CommonOpenFileDialog package so that I can refer to it?

haruya
  • 37
  • 8

2 Answers2

0

This works, you must simply install it using Install NuGet packages. Search for WindowsAPICodePack-Shell, then install it for your project.

Next, make sure the Microsoft.WindowsAPICodePack and Microsoft.WindowsAPICodePack.Shell DLLs are visible in the dependency list.

Make sure there is using Microsoft.WindowsAPICodePack.Dialogs; declaration in the file where you are using the control.

If you are using it in a console application, add [STAThread] right above the static void Main(string[] args).

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
-2

You could use the System.Windows.Forms.OpenFileDialog for opening files, it contains the properties InitialDirectory and Multiselect.

For opening folders, you could use System.Windows.Forms.FolderBrowserDialog . With this class, you would need to use the property RootFolder to choose where the browsing starts from.

Benedict H.
  • 129
  • 7