tags:

views:

67

answers:

3

I am using my own Custom View to show the files and folders and also using a search box to jump to a specific folder. In that case How to send a message to File Open/Save dialog to enforce it to change the current displayed folder.

e.g. If the dialog shows files and folders of current displaying folder "C:\", I want an API (or any piece of code) to enforce to change the current folder to "D:\"

+1  A: 

You can have the dialog open at a specific directory using InitialDirectory.

If you want to control what the dialog does at runtime, that's a bit more complex.

Codesleuth
+1  A: 

Set SaveFileDialog.InitialDirectory after you create it, but before you open it.

For example:

Stream myStream = null;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();

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

if(saveFileDialog1 .ShowDialog() == DialogResult.OK)
{
    try
    {
        if ((myStream = saveFileDialog1 .OpenFile()) != null)
        {
            // Code to write the stream goes here.
            myStream.Close();

        }
    }
    catch (Exception ex)
    {
        MessageBox.Show("Error: Could not save file to disk. Original error: " + ex.Message);
    }
}
ChrisBD
A: 

set InitialDirectory property to any path

Space Cracker