I have this situation in c# application
have 2 paths in my windows
and i need get related path of second related with first like this:
Exists a way to do this in c# or some one have a function can help me
Uri first = new Uri(@"C:\Projectos2\CSoft.Core"); Uri second = new Uri(@"C:\Projectos\FrameworkCS\CSoft.Core "); string relativePath = second.MakeRelativeUri(first).ToString();
I would probably figure it out by splitting both using the '\' as a separator. I would then count array items that were the same to get my common bond. Then I would build the destination path using the remaining items in the destination array and build the ..\ string by counting the remaining items in the source.
Join the ..\ with the CSoft.Core giving you ..\CSoft.Core
Addendum: I didn't realise you could use the URI.MakeRelativePath() method for this - don't bother reinventing the wheel if it's already been done elsewhere.