0

With the absolute path stated below, how can I convert it to be a relative path?

System.IO.FileInfo path = new System.IO.FileInfo(@"C:\Users\username\Documents\GitHub\MassSpecStudio\MassSpecStudio 2.0\source\MassSpecStudio\Core\app.config");

My initial attempt was

System.IO.FileInfo path = new System.IO.FileInfo(@"..\..\..\..\..\MassSpecStudio\MassSpecStudio 2.0\source\MassSpecStudio\Core\app.config");

but this path cannot be found so I guess my attempt is incorrect.

DanCode
  • 525
  • 3
  • 7
  • 25
  • 2
    possible duplicate of [Absolute to Relative path](http://stackoverflow.com/questions/13266756/absolute-to-relative-path) – Flynn1179 Aug 13 '15 at 17:30
  • Relative to my C drive. – DanCode Aug 13 '15 at 17:50
  • 1
    You're sure about your current path? Try to use `System.IO.Directory.GetCurrentDirectory` to see your working directory. – Fer García Aug 13 '15 at 17:55
  • 1
    It occurred to me your question's actually a bit ambiguous. Do you want to know how to get C# to do the conversion, or are you asking how you can do it yourself? If so, I suspect what you REALLY want is `Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),"GitHub\MassSpecStudio\[etc..]")` – Flynn1179 Aug 13 '15 at 18:10
  • relative path come with respect to some file for process. maybe you are trying to access app.config related to "yourapplication.exe" file then put related path related to that exe. (ex : app is MassSpecStudio\app\app.exe then "..\..\core\app.config") – Jophy job Aug 13 '15 at 18:10
  • The GetCurrentDirectory states that my working directory is at C:\Users\username\Documents\GitHub\MassSpecStudio\MassSpecStudio 2.0\Output\bin – DanCode Aug 13 '15 at 18:26

0 Answers0