title: C# path to certain parent directory
body: <p>Is there a short way to get certain parent directory path from current path.</p>
  
  <p>I have a path like this: </p>
  
  <pre><code>"c:\\users\\userName\\documents\\visual studio 2013\\Projects\\SolutionName\\ProjectName\\bin\\Debug"
  </code></pre>
  
  <p>and i want to get the path to 'SolutionName' directory, like this</p>
  
  <pre><code>"c:\\users\\userName\\documents\\visual studio 2013\\Projects\\SolutionName"
  </code></pre>
  
  <p>I need it because i am storing some data in folder </p>
  
  <pre><code>"c:\\users\\userName\\documents\\visual studio 2013\\Projects\\SolutionName\\DataFolder"
  </code></pre>
  
  <p>and i need to access it from different projects in my solution.</p>
  
  <p>Thank you all, there is what i finished with</p>
  
  <pre><code>public static string GetParent( string parentName,string FileName)
      {
          var dir = new DirectoryInfo(System.IO.Directory.GetCurrentDirectory());
  
          while (dir.Parent.Name != parentName)
          {
              dir = dir.Parent;
          }
          return dir.Parent.FullName+"\\Data\\"+FileName;
      }
  </code></pre>
  
  <p>I accepted Callum Bradbury answer because i just changed it not to be recursive.</p>