Get relative Path of a file C#
<p>I currently writing a project in visual studio in c#.
the project full path is:</p>

<pre><code>"C:\TFS\MySolution\"
</code></pre>

<p>I have a file that I need to load during the execution. lets say the file path is</p>

<pre><code>"C:\TFS\MySolution\Project1\NeedtoLoad.xml"
</code></pre>

<p>I don't want to write the full path hard coded, and want to get the path in a dynamic way. </p>

<p>I use the following line:</p>

<pre><code>    var path = Directory.GetCurrentDirectory();
</code></pre>

<p>The problem that every method that I found and the above code line gets me the following path:</p>

<pre><code>"C:\TFS\MySolution\Project1\bin\Debug"
</code></pre>

<p>And what I need is</p>

<pre><code>"C:\TFS\MySolution\Project1\"
</code></pre>

<p>so I could concatenate </p>

<pre><code>NeedtoLoad.xml
</code></pre>

<p>to the answer.</p>

<p>of course I could do:</p>

<pre><code>path.Substring(0, path.IndexOf("bin\\Debug"));
</code></pre>

<p>But it is not that elegant. </p>