0

I'm trying to set a relative path to another project in the same solution. I have a solution with 2 projects (projectA, projectB). The program starts with projectA, on a form of projectA there is a button "proceed to projectB". When clicked a form of projectB is opened. on this form I'm trying to load text files like this:

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

The problem here is that I get an FileNotFoundExeption. Since the program looks for textfile.txt in projectA debug folder.

C:\Users\ben\Documents\Project\projectA\bin\Debug

But the textfile is actually located in the projectB debugfolder.

C:\Users\ben\Documents\Project\projectB\bin\Debug

How can I change the path so that the program searches in projectB debug folder?

Thanks in advance.

Community
  • 1
  • 1
user3644837
  • 335
  • 2
  • 3
  • 8

1 Answers1

0

Why not just make both projects output their binaries in a common folder?

C:\MyFolder\Project A -> C:\MyFolder\Output

C:\My Folder\Project B -> C:\MyFolder\Output

This way the above code will work.

Ganesh R.
  • 4,337
  • 3
  • 30
  • 46