File open / save dialog
I use my own custom view to show files and folders and also use the search box to navigate to a specific folder. In this case, How to send a message to the "Open / Save File" dialog to force the application to change the currently displayed folder.
eg. If the dialog shows the files and folders of the currently displayed folder "C: \", I want the API (or any piece of code) to enforce to change the current folder to "D: \"
+2
a source to share
3 answers
You can open a dialog in a specific directory using InitialDirectory
.
If you want to control what the dialog does at runtime, this is a little more complicated.
+2
a source to share
Set SaveFileDialog.InitialDirectory after creating it but before opening it.
For instance:
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);
}
}
+2
a source to share