Freelance Project Requests info@CodeDocu.de Software Development in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net
#

WPF: Filedialog
 
This example shows how to create a file dialog under Window WPF Applications to mark and apply multiple files.
The dialog for selecting files is OpenFileDialog ()

Microsoft.Win32.OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.Multiselect = true;

 
Filter for file extensions and the default is set to .Filter.
In this case, a title and filter pattern are entered in pairs as Log Files | * .log

fileDialog.Filter = "Log Files|*.log|Textfiles|*.txt|All Files|*.*";
fileDialog.DefaultExt = ".log";
 

 
Final, the dialog with ShowDialog () is opened and checked to see if something has been entered

Nullable<bool> dialogOK =fileDialog.ShowDialog();
 
if (dialogOK == true)
{
..selected files
}

 
 
Display the FileDialog under Windows 10

 
 

OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.Multiselect = true;
fileDialog.Filter = "Log Files|*.log|Textfiles|*.txt|All Files|*.*";
fileDialog.DefaultExt = ".log";
Nullable<bool> dialogOK =fileDialog.ShowDialog();
 
if (dialogOK == true)
{
string sFilenames = "";
//------< @Loop: Filenames >--------
foreach (string sFilename in fileDialog.FileNames)
{
//collect string
sFilenames += ";" + sFilename;
}
sFilenames = sFilenames.Substring(1); //delete first ;
//------</ @Loop: Filenames >--------
 
tbxFiles.Text = sFilenames;
}

 
 
As Namespace you have to expand under Using Microsoft.Win32

//--< using >--
using Microsoft.Win32; //FileDialog
//--</ using >--

 
 
 
Video Tutorial
Mobile
»
WPF: Explorer with path open
»
WPF: Open a Window at a position
»
WPF: Selection enter open and well take over with Button Elements
»
WPF: Select Folder with Startup Directory
»
WPF: FolderDialog and GetFiles
»
Error CS0234: The type or namespace name Forms does not exist in the namespace
»
WPF: Filedialog, OpenFileDialog

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de