tags:

views:

6348

answers:

2
+1  Q: 

C# Save Dialog box

I've got a save dialog box which pops up when i press a button. However i dont want to save a file at that point, i want to take the name and place it in the text box next to the button, for the name to be used later.

Can anybody tell me how to obtain the file path from the save dialog box to use it later?

+9  A: 

Here is a sample code I just wrote very fast... instead of Console.Write you can simply store the path in a variable and use it later.

SaveFileDialog saveFileDialog1 = new SaveFileDialog(); 
saveFileDialog1.InitialDirectory = Environment.SpecialFolder.MyDocuments; 
saveFileDialog1.Filter = "Your extension here (*.EXT)|*.ext|All Files (*.*)|*.*" ; 
saveFileDialog1.FilterIndex = 1; 

if(saveFileDialog1.ShowDialog() == DialogResult.OK) 
{ 
 Console.WriteLine(saveFileDialog1.FileName);//Do what you want here
}
Daok
+1  A: 

Addressing the textbox...

if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
    this.textBox1.Text = saveFileDialog.FileName;
}
JTA