Microsoft Communities

Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How do I use the OpenFileDialog?

using System.Text; 
using System.IO;

private string ChooseTextFile( string initialDirectory ) 
{ 
  OpenFileDialog dlg = new OpenFileDialog(); 
  dlg.Title = "Open text file"; 
  dlg.InitialDirectory = initialDirectory; 
  dlg.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; 
  return ( dlg.ShowDialog() == DialogResult.OK )
    ? dlg.FileName : null;
}

Contributed from George Shepherd's Windows Forms FAQ



Page view counter