I'm getting an incorrect path when using MakeRelativeUri. Now this could be an issue with Unity and mono or hopefully I'm just using it wrong or maybe there's actually a bug in .net. You'll have to forgive the elaborate example but this is what I have.
System.Uri fileURI = new System.Uri( "/Home/Folder1/Folder2/Folder3/Folder4/Folder5/Folder6/../../../../Folder7/Folder8/file.png" );
System.Uri rootURI = new System.Uri( "/Home/Folder1/Folder2/Folder3/../FolderA/." );
result = rootURI.MakeRelativeUri( fileURI ).ToString();
result in this case is ../../Folder4/Folder5/Folder6/../../../../Folder7/Folder8/file.png
but it should be
../Folder3/Folder4/Folder5/Folder6/../../../../Folder7/Folder8/file.png
It seems as though it is treating the ../ in the root path as a directory rather than an instruction to go back a directory. Can anyone confirm if thats the case?
I've worked around this by passing the path strings through Path.GetFullPath() before passing them into the Uri constructor. That strips out the ../ correctly and this then works as you would expect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With