搜索按钮而不创建新文件C ++

时间:2015-08-07 09:07:07

标签: c++ visual-studio-2010 button filepath savefiledialog

我想打开一个对话框来搜索文件路径,而没有创建文件,只保存文本框中的路径文件。

这是我已经得到的,但它创建了一个新文件:

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();
        }
    }

1 个答案:

答案 0 :(得分:0)

调用OpenFile是创建文件的原因。不要这样做。

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;                  
}