tags:

views:

143

answers:

2

I have a windows form application I have a button that opens the SaveFileFrom dialog

private void button1_Click(object sender, EventArgs e)
{
  SaveFileDialog savefileDialog1 = new SaveFileDialog();
  savefileDialog1.ShowDialog();
}

I was wondering how I could put the file that is chosen in a text box even like so

private void textBox1_TextChanged(object sender, EventArgs e)
{

}

UPDATE* Ok, well since the user might want to open more than one file to save I wanted to take off my button SaveFileFrom and instead make the textbox run through the OpenFileDialog when clicked. Also, is their a way to make a text link instead of a button? Like I want a text link to add another text box/

+4  A: 

Try this

private void button1_Click(object sender, EventArgs e)
{
  SaveFileDialog savefileDialog1 = new SaveFileDialog();
  if (savefileDialog1.ShowDialog() == DialogResult.OK)
  {
    textBox1.Text = savefileDialog1.Filename;
  }
}
bendewey
beat me to it, good answer :)
John T
A: 

The filename selected will be saved in SaveFileDialog.FileName

example:

private void button1_Click(object sender, EventArgs e)
{

SaveFileDialog SvDlg = new SaveFileDialog();

  if (SvDlg.ShowDialog() == DialogResult.OK)
  {
      textBox1.Text = SvDlg.FileName;
  }
  else 
  {
      MessageBox.Show("No file selected.");
  }

}
John T