C#

[C#] How to: Use the Open File Dialog Box

rex0725 2016. 7. 2. 00:08

https://msdn.microsoft.com/en-us/library/cc221415(v=vs.95).aspx


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Create an instance of the open file dialog box.
Microsoft.Win32.OpenFileDialog openFileDialog1 = new Microsoft.Win32.OpenFileDialog();
 
// Set filter options and filter index.
openFileDialog1.Filter = "Text Files (.txt)|*.txt|All Files (*.*)|*.*";
openFileDialog1.FilterIndex = 1;
 
// Call the ShowDialog method to show the dialog box.
bool? userClickedOK = openFileDialog1.ShowDialog();
 
// Process input if the user clicked OK.
if (userClickedOK == true)
{
    // Do some
    openFileDialog1.FileName;
}
cs