Open File Dialog in C#
To create an OpenFileDialog window in C# you can create a new object usingOpenFileDialog()
from using System.Windows.Forms;
namespace, next you will check whether ShowDialog()
Method is returning a DialofResult.OK
property, Finally you can get the selected file using the property FileName
Example
using System;
using System.Windows.Forms;
public class Program
{
public static void Main()
{
OpenFileDialog dialog = new OpenFileDialog();
if (DialogResult.OK == dialog.ShowDialog())
{
string path = dialog.FileName;
}
}
}