U.B.A.R
U.B.A.R

Reputation: 231

Getting only the folder path by browse button

I am getting a complete path of a file by browsing through the folder and selecting a file after i click browse button.

But i want to get path upto the folder only by browsing.

I did the following for the file path

                 Stream^ myStream;  
                 OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;

                 openFileDialog1->InitialDirectory = "c:\\";
                 //openFileDialog1->Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
                 openFileDialog1->FilterIndex = 2;
                 openFileDialog1->RestoreDirectory = true;

                 if ( openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK )
                 {
                     if ( (myStream = openFileDialog1->OpenFile()) != nullptr )
                     {                               

                         String^ p1 = openFileDialog1->FileName; 


                         MessageBox ::Show (p1);

                         myStream->Close();
                     }

Upvotes: 2

Views: 1861

Answers (1)

Chad
Chad

Reputation: 19032

For getting folder paths rather than file names, use FolderBrowserDialog

Upvotes: 1

Related Questions