using System.Windows.Forms; OpenFileDialog openFileDialog1 = new OpenFileDialog(); // Show the dialog and get the result. DialogResult result = openFileDialog1.ShowDialog(); if (result == DialogResult.OK) { // Do something with the selected file(s)... } // Call Dispose method to release unmanaged resources used by the dialog box openFileDialog1.Dispose();
using System.Windows.Forms; using (OpenFileDialog openFileDialog1 = new OpenFileDialog()) { // Show the dialog and get the result. DialogResult result = openFileDialog1.ShowDialog(); if (result == DialogResult.OK) { // Do something with the selected file(s)... } }In this example, we use the Dispose method in a using statement. This ensures that the Dispose method is called automatically when the object is no longer needed. Package library: System.Windows.Forms.