Hi Rizaan,
Well - your problem makes sense but I can't think of a simple solution to be
honest - sorry !
It seems to me that the best approach is something along these lines:
Take the absolute paths of your project file and your class file
e.g.
string projPath = "c:\dev\projects\myProj\myProj.csproj"
string classPath = "c:\dev\projects\myProj\src\blah\class1.cs"
Now examine these two paths and chop off the common part at the start of the
path
projPath = "myProj.csproj"
classPath = "src\blah\class1.cs"
Now parse the longer of the paths, generating a relative path. e.g. every
time you hit a \ symbol, add a .. to your rel path etc.
This should work but there are a number of caveats that spring to mind:
- will the two paths always be in the same format? ie file://c:\dev.... vs
c:\dev....
- will the root be quoted in the same way? ie c:\dev... vs
\\mymachine\c$\dev....
- will the slashes be the same way round ?
- etc
Hope this helps a bit, sorry for not having a more elegant solution.
Regards,
Rob
http://roblevine.blogspot.com