title: Converting absolute path to relative path C#
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/703281/getting-path-relative-to-the-current-working-directory">Getting path relative to the current working directory?</a>  </p>
  </blockquote>
  
  
  
  <p>I have code in C# that includes some images from an absolute path to a relative so the image can be found no matter where the application fold is located. </p>
  
  <p>For example the path in my code (and in my laptop for the image) is </p>
  
  <pre><code>C:/something/res/images/image1.jpeg
  </code></pre>
  
  <p>and I want the path in my code to be</p>
  
  <pre><code>..../images/image1.jpeg 
  </code></pre>
  
  <p>So it can run wherever the folder is put, whatever the name of the <code>C:</code> partition is etc. </p>
  
  <p>I want to have a path in my code which is independant of the application folder location or if it is in another partition, as long as it is in the same folder as the the rest of the solution.</p>
  
  <p>I have this code:</p>
  
  <pre><code> try 
   { 
       File.Delete("C:/JPD/SCRAT/Desktop/Project/Resources/images/image1.jpeg");
   } 
   catch (Exception) 
   { 
        MessageBox.Show("File not found:C:/Users/JPD/Desktop/Project/images/image1.jpeg");
    } 
  </code></pre>
  
  <p>This code only runs if the file and folder are in that certain path, (which is also the location of the code) I wish for that path to be relative so wherever I put the whole folder (code, files etc) the program will still work as long as the code (which is under project folder) is at the same location with the folder images... what should I do?</p>