Select either a file or folder from the same dialog in .NET

后端 未结 10 2037
别跟我提以往
别跟我提以往 2020-12-01 10:14

Is there an \"easy\" way to select either a file OR a folder from the same dialog?

In many apps I create I allow for both files or folders as input. Until now i alwa

相关标签:
10条回答
  • 2020-12-01 11:12

    The Ookii Dialogs implement a folder browser dialog that allow for both files or folders as input, and is available for Windows Forms and WPF.

    Ookii.Dialogs.Wpf

    https://github.com/augustoproiete/ookii-dialogs-wpf


    Ookii.Dialogs.WinForms

    https://github.com/augustoproiete/ookii-dialogs-winforms

    0 讨论(0)
  • 2020-12-01 11:14

    You can use standard OpenFileDialog to select a folder. Here is an article in CodeProject that demonstrated a way to do it (http://www.codeproject.com/KB/dialog/OpenFileOrFolderDialog.aspx).

    0 讨论(0)
  • 2020-12-01 11:15

    Technically, it is possible. The shell dialog used by FolderBrowseDialog has the ability to return both files and folders. Unfortunately, that capability isn't exposed in .NET. Not even reflection can poke the required option flag.

    To make it work, you'd have to P/Invoke SHBrowseForFolder() with the BIF_BROWSEINCLUDEFILES flag turned on in BROWSEINFO.ulFlags (value = 0x4000). The P/Invoke is gritty, it is best to copy and paste the code from another source or the FolderBrowseDialog class itself with Reflector's help.

    0 讨论(0)
  • 2020-12-01 11:17

    AFAIK, there is nothing in the .NET framework that does this out of the box.

    The .NET file dialogs derive from CommonDialog:

    Inherited classes are required to implement RunDialog by invoking ShowDialog to create a specific common dialog box. Inherited classes can override HookProc to implement specific dialog box hook functionality.

    0 讨论(0)
提交回复
热议问题