Reputation: 3014
I have a start up project called Admin. It calls a method in another project called Data. Data reads an XML located in the folder Data.dll is in. But the path i get is wrongly looking in the Admin project folder.
Ive tried (from ther Data project )
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"BookSource\Book.Xml");
Path.Combine(Environment.CurrentDirectory, @"BookSource\", "Book.Xml")
Both of them looks in ..Admin\Bin\Debug\BookSource\Book.Xml instead of ..Data\Bin\Debug\BookSource\Book.Xml
I assume its because Admin starts the solution. So how can i get the path to another project than the starting project?
Upvotes: 1
Views: 97
Reputation: 2731
Make sure that your XML file is marked as "Copy Always" in its properties and then just use the filename. When the DLL from your data project is coppied into the bin directory of your Admin project, this setting will let the compiler know that it should also make a copy of the XML file in the destination location.
In solution explorer, right click your XML file and choose properties
Now under Copy to Output Directory choose Copy always
In my Class1.cs example I have the following code which returns true when called from Program.cs:
public static bool LookForFile()
{
return File.Exists("XMLFile1.xml");
}
Upvotes: 2