Windows Forms openfiledialog problem

Ok guys. I am doing a multiform windows application. I have a static library where i have functions for working with linked list. There is a function that saves the whole linked list into a binary text file. And a function that reads from a file. When the form 1 is activated i read the linked list from a file. The problem is when i open the openFileDialog on the second form, and change the directory to select a file which is on desktop for example. I save that path of a file in a System string variable then i close down the form 2. Now first form has nothing to do with the open file dialog, and when the 1form is activated again (when i close down the form 2 the form 1 activates) it cannot read from a file and closes down the program.

void beri_iz_datoteke(char *ime_dat, vozel*& zac)
{
ifstream dat;
dat.open(ime_dat,ios::binary);
if(!dat) // if a file isn't opened
{
dat.clear();
exit(1); // closes down the program
}
int st_vozlov;
dat.seekg(0,ios::end);
st_vozlov=dat.tellg()/sizeof(vozel);
dat.seekg(0);
for(int i=0;i<st_vozlov;i++)
{
vozel *temp=nov_vozel(zac);
dat.read((char*)temp,sizeof(vozel));
dodaj_na_konec(zac,temp);
}
dat.close();

}
But now my question is why the file cannot be opened? This is only when i open the open file dialog otherwise there is no problem with opening the file.

Here is code of form 2:

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
if(openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
textBox1->Text=openFileDialog1->FileName;
pot=Convert::ToString(openFileDialog1->FileName);


}
}
Topic archived. No new replies allowed.