How do i open a file in C++ (Windows Form Application)

closed account (LAfSLyTq)
i have used microsofts own code and all they did was confuse me and cause errors, have to restart now... can somone tell me how to open a file without a dialog box by clicking a button?
Within your button click handler you can use the standard ifstream or if you want the .NET equivalent. The dialog box is only for getting the file name.
closed account (LAfSLyTq)
i need the program to do this without a dialog, please read the description before posting
See http://msdn.microsoft.com/en-us/library/system.io.streamreader%28v=vs.71%29.aspx and http://msdn.microsoft.com/en-us/library/aa328778%28v=vs.71%29.aspx
1
2
3
4
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {				 
				 StreamReader^ sr = gcnew StreamReader("test.txt");
				 label1->Text = sr->ReadLine();
			 }
closed account (LAfSLyTq)
thanks for your help, but that makes a text reader, im trying to open a file as in run the file...
There's only two parts to this, opening a file and handling a callback. You've been given code for both. If you still have problems, maybe you're not asking the right question.
closed account (LAfSLyTq)
my question is why wont the program i made save the file to the correct location.
and how do i fix thyis, ive done everything you guys have suggested and it just give me errors.
my question is why wont the program i made save the file to the correct location.
That's new, no wonder you weren't getting a relevant answer.

Specify the full path+file name when you open the file.

If you don't specify the path, the file is opened in the current directory, and that isn't always what you think it is. To see the current directory, see GetCurrentDirectory.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa364934%28v=vs.85%29.aspx

i need the program to do this without a dialog, please read the description before posting
Check yourself before you start pointing the finger at others.
Last edited on
Invader2010 wrote:
thanks for your help, but that makes a text reader, im trying to open a file as in run the file...
You asked how to open a file. If you want to execute an external binary try
1
2
3
using namespace System::Diagnostics;
...
Process::Start("notepad.exe");

If not, try being a little more descriptive with what you are looking for.
closed account (LAfSLyTq)
c1075 c2059 c2238 errors, why?
Invader2010 wrote:
c1075 c2059 c2238 errors, why?
Have you looked up the error codes? http://msdn.microsoft.com/en-us/library/8x5x43k7%28v=vs.71%29

Help us help you, provide more information.
Topic archived. No new replies allowed.