What I am trying to achieve is to select multiple folders and files simultaneously from the OpenFileDialog.
The suggested solution of setting:
The suggested solution of setting:
![Files Files](https://docs.telerik.com/devtools/wpf/controls/radfiledialogs/dialog-controls/images/radopenfiledialog-01.png)
This setting fails for the use case when the user selects a folder and a file simultaneously.
Jul 28, 2011 Hi Guys, I have a set of files which I am planning to Decrypt, but first i need to select multiple files and then display them in a text box, I will not be.
I am looking for a solution via which I can close the dialog when the user presses the open button and get the path for the selected file(s) and folder(s).
Hemant BhattHemant Bhatt
1 Answer
I think this question has already been answered here
I'll repeat it:
If you use the FileNames property instead of the FileName property, you get a string array of each file selected, you select multiple files using the shift key. Like so:
For files and folders you need to use the
CommonOpenFileDialog
included with the WinAPI, the particular class is here.Community♦
Samy S.RathoreSamy S.Rathore
Not the answer you're looking for? Browse other questions tagged c#openfiledialog or ask your own question.
-->System.Windows.Forms.OpenFileDialog Компонент открывает диалоговое окно Windows для просмотра и выбора файлов.The System.Windows.Forms.OpenFileDialog component opens the Windows dialog box for browsing and selecting files.Чтобы открыть и прочитать выбранных файлов, можно использовать OpenFileDialog.OpenFile метод, или создать экземпляр System.IO.StreamReader класса.To open and read the selected files, you can use the OpenFileDialog.OpenFile method, or create an instance of the System.IO.StreamReader class.В следующих примерах оба подхода.The following examples show both approaches.
В .NET Framework, для получения или задания FileName свойство требуется уровень привилегий предоставляемый System.Security.Permissions.FileIOPermission класса.In .NET Framework, to get or set the FileName property requires a privilege level granted by the System.Security.Permissions.FileIOPermission class.Примеры выполняют FileIOPermission разрешение проверки и может создавать исключения из-за недостатка привилегий, если выполняются в контексте частичного доверия.The examples run a FileIOPermission permission check, and can throw an exception due to insufficient privileges if run in a partial-trust context.Дополнительные сведения см. в разделе основы управления доступом для кода.For more information, see Code access security basics.
Можно создавать и запускать эти примеры приложений .NET Framework из C# или командной строки Visual Basic.You can build and run these examples as .NET Framework apps from the C# or Visual Basic command line.Дополнительные сведения см. в разделе сборка с помощью csc.exe из командной строки или построения из командной строки.For more information, see Command-line building with csc.exe or Build from the command line.
Начиная с .NET Core 3.0, вы можете также создавать и выполнять примеры как Windows приложений .NET Core из папки с .NET Core Windows Forms <имя_папки > .csproj файл проекта.Starting with .NET Core 3.0, you can also build and run the examples as Windows .NET Core apps from a folder that has a .NET Core Windows Forms <folder name>.csproj project file.
Пример Чтение файла в виде потока с помощью StreamReaderExample: Read a file as a stream with StreamReader
В следующем примере используется Windows Forms Button элемента управления Click обработчик событий, чтобы открыть OpenFileDialog с ShowDialog метод.The following example uses the Windows Forms Button control's Click event handler to open the OpenFileDialog with the ShowDialog method.Когда пользователь выберет файл, а также выбирает ОК, экземпляр StreamReader класс читает файл и выведет его содержимое в текстовое поле формы.After the user chooses a file and selects OK, an instance of the StreamReader class reads the file and displays its contents in the form's text box.Дополнительные сведения о чтении из файловых потоков, см. в разделе FileStream.BeginRead и FileStream.Read.For more information about reading from file streams, see FileStream.BeginRead and FileStream.Read.
Пример Откройте файл из отфильтрованные объекты с помощью OpenFileExample: Open a file from a filtered selection with OpenFile
![Files Files](https://csharpcorner-mindcrackerinc.netdna-ssl.com/UploadFile/mahesh/openfiledialog-in-C-Sharp/Images/OpenFileDlgImg1.jpg)
В следующем примере используется Button элемента управления Click обработчик событий, чтобы открыть OpenFileDialog с фильтром, который показывает только текстовые файлы.The following example uses the Button control's Click event handler to open the OpenFileDialog with a filter that shows only text files.Когда пользователь выберет в текстовый файл, а также выбирает ОК, OpenFile метод используется, чтобы открыть файл в блокноте.After the user chooses a text file and selects OK, the OpenFile method is used to open the file in Notepad.