now i'm trying to use the openfiledialog in a gui app .. what i have done till now is that
1. open visual stdio 2008
2. select c++ project
3. select windows application project
4. drag the openfile dialog from tool box and drop it on the form .. then i stopped coz i don't know what should i do after that

plz any one can help me !!

6 Years
Discussion Span
Last Post by jonsca

Within the body of a button click method (of a button with the text "Open" or some such)

openFileDialog1->InitialDirectory = "C:\\";  //set the initial directory for the dlg
openFileDialog1->Filter = "All Files(*.*)|*.*"; //set a filter for the types of files
openFileDialog1->FileName = ""; //leave the textbox blank
Windows::Forms::DialogResult dr = openFileDialog1->ShowDialog(); //show the dialog

After that, compare dr with Windows::Forms::DialogResult::OK (need the fully qualified name) and openFileDialog1->FileName will contain the name file the user selected. Use this name, for instance, in a StreamReader call to open a text file.

See http://msdn.microsoft.com/en-us/library/system.windows.forms.openfiledialog_members.aspx to get an idea of some of the other members that are available.

Edited by jonsca: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.