Hi - I'm trying to get the filename and path of a file I'm opening with the OpenFileDialog in Visual C++. I can open and display the contents of the file OK, but I'm having problems accessing the filename and path, I guess they're stored in a structure somewhere? Code so far below...Thanks in advance!

private: System::Void button1_Click(System::Object *  sender, System::EventArgs *  e)
				if(openFileDialog1->ShowDialog() == DialogResult::OK)
					String* get_FileNames();
					System::IO::StreamReader * sr = new


Recommended Answers

All 2 Replies

I've been working on that very thing the past few days -- learning Windows Forms. You can't call c++ new operator -- instead you have to use gcnew.

private: System::Void toolStripMenuOpen_Click(System::Object^  sender, System::EventArgs^  e) {

             if( openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
                    StreamReader^ myStream;
                    if(openFileDialog1->FileName == nullptr)
                    if ((myStream = gcnew StreamReader(openFileDialog1->FileName)) != nullptr)

Thanks Ancient Dragon, I used this to display the file and path


Now today's task is to work out how I want to use it :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.