Hey again ...:P

Now i have problem with save & load from/to text file.

private: System::Void załadujPlaylisteToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {

			  OpenFileDialog^ dig = gcnew OpenFileDialog();
			  dig->Filter = "PlayList(*.PLS)|*.PLS";
			  if(dig->ShowDialog() == System::Windows::Forms::DialogResult::OK)
			  {
				  listBox1->Items->Add(IO::File::ReadAllText(dig->FileName));
			  }

		 }
private: System::Void zapiszPlaylisteToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
			 SaveFileDialog^ dig = gcnew SaveFileDialog();
			 dig->Filter = "PlayList(*.PLS)|*.PLS";
			 if(dig->ShowDialog() == System::Windows::Forms::DialogResult::OK)
			 {
				 System::IO::File::WriteAllText(dig->FileName, listBox1->Items);
			 }
		 }

How i can do that?
Anyone can write some example?
Thx for read that :P

Use a streamreader for the first one, a streamwriter for the second.

StreamReader ^ sr = gcnew StreamReader(filename);
String ^ temp;
while(temp = sr->ReadLine())
    listBox1->Items->Add(temp);

Use a streamreader for the first one, a streamwriter for the second.

StreamReader ^ sr = gcnew StreamReader(filename);
String ^ temp;
while(temp = sr->ReadLine())
    listBox1->Items->Add(temp);
1>c:\users\yourmomy\documents\visual studio 2010\projects\program 2\program 2\Form1.h(227): error C2065: 'StreamReader' : undeclared identifier
1>c:\users\yourmomy\documents\visual studio 2010\projects\program 2\program 2\Form1.h(227): error C2065: 'sr' : undeclared identifier
1>c:\users\yourmomy\documents\visual studio 2010\projects\program 2\program 2\Form1.h(227): error C2061: syntax error : identifier 'StreamReader'
1>c:\users\yourmomy\documents\visual studio 2010\projects\program 2\program 2\Form1.h(229): error C2065: 'sr' : undeclared identifier
1>c:\users\yourmomy\documents\visual studio 2010\projects\program 2\program 2\Form1.h(229): error C2227: left of '->ReadLine' must point to class/struct/union/generic type
1>          type is ''unknown-type''
1>c:\users\yourmomy\documents\visual studio 2010\projects\program 2\program 2\Form1.h(229): fatal error C1903: unable to recover from previous error(s); stopping compilation

o.O

Oh, sorry. You need a using namespace System::IO; up at the top (or qualify each like System::IO::StreamReader )

Oh, sorry. You need a using namespace System::IO; up at the top (or qualify each like System::IO::StreamReader )

omm my bad >.< sorry for problem :P you are really helpfull thx!

ok streamreader work.

but steamwriter... How to save listBox??

SaveFileDialog^ dig = gcnew SaveFileDialog();
			 dig->Filter = "PlayList(*.PLS)|*.PLS";
			 if(dig->ShowDialog() == System::Windows::Forms::DialogResult::OK)
			 {
				StreamWriter^ pwriter = gcnew StreamWriter(dig->FileName);
				
				pwriter->WriteLine(listBox1->ToString);
				
				pwriter->Close();

			 }

It's my code but dont work >.<

Happy new year ^^

This article has been dead for over six months. Start a new discussion instead.