-2

I want to open a dialog to search for a filepath, without already creating the File and only saving the pathfile in a textBox.

This is what I already got, but it creates a new file:

System::IO::Stream^ myStream;   
    SaveFileDialog^ saveFileDialog1 = gcnew SaveFileDialog;
    saveFileDialog1->Filter = "txt files (*.txt)|*.txt";
    saveFileDialog1->FilterIndex = 2;
    saveFileDialog1->RestoreDirectory = true;
    if ( saveFileDialog1->ShowDialog() == ::DialogResult::OK )      
    {
        if ( (myStream = saveFileDialog1->OpenFile()) != nullptr )
        {
            textBox->Text = saveFileDialog1->FileName;                  
            myStream->Close();
        }
    }
Community
  • 1
  • 1
beheim
  • 1
  • 4

1 Answers1

0

Calling OpenFile is what's creating the file. Don't do it.

System::IO::Stream^ myStream;   
SaveFileDialog^ saveFileDialog1 = gcnew SaveFileDialog;
saveFileDialog1->Filter = "txt files (*.txt)|*.txt";
saveFileDialog1->FilterIndex = 2;
saveFileDialog1->RestoreDirectory = true;
if ( saveFileDialog1->ShowDialog() == ::DialogResult::OK )      
{
    textBox->Text = saveFileDialog1->FileName;                  
}
Will
  • 2,512
  • 14
  • 19
  • Now I see the answer I feel stupid, but thanks a lot! I addet this line : saveFileDialog1->OverwritePrompt = false; because I want to handle the problems later. – beheim Aug 07 '15 at 11:37