0

Got another problem. I have a solution "solution1" in this solution are 3 projects "projectA" , "projectB", "projectC". I have made a reference to projectB & projectC from projectA. I have added the 2 other projects to my solution folder which contains my projectA already. I've added them in solution explorer and made a reference as I said.

Now when I click a button on a form from projectA:

    private void formProjectAButton_Click(object sender, EventArgs e)
    {
        this.Hide();
        projectB.Form1 fs = new projectB.Form1();         
        fs.Show();
    }

the form from projectB shows no problem. But then when I use the form from projectB (which contains a picturebox and a textbox. The picturebox just contains a static image which is located in my bin/debug folder. The textbox contains text that I load when the picturebox is clicked):

    private void picturebox1_Click(object sender, EventArgs e)
    {
        textBox1.Text = "";



            inputStream = File.OpenText("gebod1.txt");
            string line = inputStream.ReadLine();
            while (line != null)
            {
                textBox1.AppendText(line);
                line = inputStream.ReadLine();
            }



        textBox1.Visible = true;
    }

But now when I click the picturebox to load the text from the textfile (which is in projectB debug folder) into the textbox I get an filenotfoundexeption.

Anything I can do to fix this?

Thanks in advance.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
user3644837
  • 335
  • 2
  • 3
  • 8

1 Answers1

1

You're using a relative path. The relative path is the current working folder.

So if you have a Project A in C:\Foo\ProjectA and Project B in C:\Foo\ProjectB, your text file in project A will be in C:\Foo\ProjectA\bin\Debug\foo.txt. You'll need to navigate to the correct folder relative to your working folder, or specify a full path.

For example, you could try something like this. Obviously, this is just an example to give you an idea of how you accomplish what you're after. File.OpenText("..\..\..\ProjectA\bin\Debug\gebod1.txt");

The .. in this context means "up one folder in the tree". So if you're in C:\Foo\Bar, a relative path of ..\Baz would mean C:\Foo\Baz\

Another option would be to add a post-build step to ProjectA to copy the file to a known folder, and then reference the file out of that location.

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120
  • Thanks for the help. But isn't there like a way so that when I click a button on form1 of projectA that projectA closes and projectB opens on it's own? And then when I click on a button on a form of projectB (like "go back to projectA form1) that projectB closes (not hide, but really closes) and projectA opens? So that I don't have to mess with the paths and that the program like opens the complete projectB. I hope you understand what I mean – user3644837 May 17 '14 at 15:39