tags:

views:

650

answers:

2
+1  A: 

Hi,

You can use FileOpenDialog and FolderBrowserDialog as per your requirement from the application.

http://www.kanbal.com/index.php?/CSharp/file-open-dialog-box-in-csharp.html

Bhaskar
link gives 404 error
beetstra
+2  A: 

from msdn

private void button1_Click(object sender, System.EventArgs e)
{
    Stream myStream = null;
    OpenFileDialog openFileDialog1 = new OpenFileDialog();

    openFileDialog1.InitialDirectory = "c:\\" ;
    openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
    openFileDialog1.FilterIndex = 2 ;
    openFileDialog1.RestoreDirectory = true ;

    if(openFileDialog1.ShowDialog() == DialogResult.OK)
    {
        try
        {
            if ((myStream = openFileDialog1.OpenFile()) != null)
            {
                using (myStream)
                {
                    // Insert code to read the stream here.
                }
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
        }
    }
}
Svetlozar Angelov
prefer also surrounding OpenFileDialog openFileDialog1 = new OpenFileDialog(); with using tags
PoweRoy
Stream myStream = null; the 'Stream' is refering to which class or reference?