Reputation: 21
I tried using @"~\TestData\Test.xml"
, it is trying to get file from bin/debug
instead of the project folder.
Upvotes: 2
Views: 18101
Reputation: 214
You can achieve this by getting the parent of the current directory, using the Directory class in System.IO namespace. See code example.
using System.IO;
namespace ConsoleApplication15
{
class Program
{
static void Main(string[] args)
{
var projectFolder = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
var file = Path.Combine(projectFolder, @"TestData\Test.xml");
}
}
}
Upvotes: 6
Reputation: 51009
Go to Solution explorer -> right click on TestData
folder and choose "Add New Item"
Choose "Resources file", rename it to Resource
and click "Add".
You will get this screen (It can also be opened by double click on "Resource.resx in the solution explorer)
Give name to the file and put the relative path in the value (may require one level up or down). To get the path you can now use
string path = Resource.XMLFile;
Upvotes: 4