0

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
					System::IO::StreamReader(openFileDialog1->FileName);
					MessageBox::Show(sr->ReadToEnd());
					sr->Close();
				}

			 }
2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by The physicist
0

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)
             {
                try
                {
                    StreamReader^ myStream;
                    if(openFileDialog1->FileName == nullptr)
                        return;
                    if ((myStream = gcnew StreamReader(openFileDialog1->FileName)) != nullptr)
                    {

Edited by Ancient Dragon: n/a

0

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

System::IO::StreamReader(openFileDialog1->FileName);
MessageBox::Show(openFileDialog1->FileName);

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

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.