Question: Some resources I have in my project are fine and working Ok using string paths but what if I move the project to another directory or to another computer, it will stop working.

Please I need to get the path of the resources folder of my project in a string variable,

Something like this

```
C:\Users\User1\Documents\<projects folder>\<project name>\Resources\

```

Thanks in advance.

Answer: 
This might not be the cleanest way, but it has been useful to me. 

If you had a structure like:

```
C:\...\MyApp\app.exe
C:\...\MyApp\ConfigFiles\MyConfig.xml

```

The code will return a path relative to the running assembly. 

```
GetPath("ConfigFiles/MyConfig.xml") // returns the full path to MyConfig.xml

private string GetPath(string relativePath)
{
    var appPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
    string pattern = @"^(.+\\)(.+exe)$";
    Regex regex = new Regex(pattern, RegexOptions.None);
    var match = regex.Match(appPath);
    return System.IO.Path.GetFullPath(match.Groups[1].Value + relativePath);
}

```
You could try to use |DataDirectory| documented [here.](http://msdn.microsoft.com/en-us/library/system.deployment.application.applicationdeployment.datadirectory(v=vs.110).aspx)

Here's a description of how it works from [an old Microsoft article](http://blogs.msdn.com/b/smartclientdata/archive/2005/08/26/456886.aspx)

> 
> One of the reasons why it was hard to work with database files before
>  is that the full path to the database was serialized in different
>  places. This made it harder to share a project and also to deploy the
>  application. In this version, the .NET runtime added support for what
>  we call the DataDirectory macro. This allows Visual Studio to put a
>  special variable in the connection string that will be expanded at
>  run-time. So instead of having a connection string like this:
> 
> 
> 
> ```
>   "Data Source=.\SQLExpress;AttachDbFileName=c:\program files\app\data.mdf"
> 
> ```
> 
> You can have a connection string like this:
> 
> 
> 
> ```
>   "Data Source=.\SQLExpress;AttachDbFileName=|DataDirectory|\data.mdf"
> 
> ```
> 
> This connection string syntax is supported by the SqlClient and OleDb
>  managed providers.
> 
> 
> By default, the |DataDirectory| variable will be expanded as follow:
> 
> 
> 
> ```
>   - For applications placed in a directory on the user machine, this will be the app's (.exe) folder.
>   - For apps running under ClickOnce, this will be a special data folder created by ClickOnce
>   - For Web apps, this will be the App_Data folder
> 
> ```
> 
>