I have two projects in my solution and project A has a reference to project B. Project A calls a function in project B that should load a document that is within Project B:
return XDocument.Load(@"Mock\myDoc.html");
The problem is that XDocument.Load
is using the path from Project A (where there is no Mock\myDoc.html
).
I have tried using
string curDir = Directory.GetCurrentDirectory();
var path = String.Format("file:///{0}/Mock/myDoc.html", curDir);
but this as well gives me a path to ProjectA\Mock\myDoc.html
when instead it should be ProjectB\Mock\myDoc.html
. What am I missing?
EDIT: "Copy to Output" for the file "myDoc.html" is set to "Copy always" and the file is available in the Output folder of Project B.
There is only one current working Directory for all of your code at runtime. You'll have to navigate up to the solution directory, then back down to the other Project.
string solutiondir = Directory.GetParent(
Directory.GetCurrentDirectory()).Parent.FullName;
// may need to go one directory higher for solution directory
return XDocument.Load(solutiondir + "\\" + ProjectBName + "\\Mock\\myDoc.html");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With