We ran into the same kind of behaviour exhibited by this post:
Why does Path.Combine produce this result with a relative path?
Where:
var basePath = @"\\server\BaseFolder";
var relativePath = @"\My\Relative\Folder";
var combinedPath = Path.Combine(basePath, relativePath);
produces an output of \My\Relative\Folder
instead of the expected \\server\BaseFolder\My\Relative\Folder
.
After reading this and other posts, as well as the MSDN doc:
If the one of the subsequent paths is an absolute path, then the combine operation resets starting with that absolute path, discarding all previous combined paths.
I understand this behaviour exactly, as well as what it's doing and how to fix it.
What I don't understand is why!
In what scenarios would this be the required behavior? Why would you ever want to pass in a set of arguments here, and have it completely ignore whatever first few you pass in and just take the last few instead?
Surely this would be better treated by Microsoft as an exception rather than just ignoring the parameters - if an absolute path is tried to be merged with a path which was already absolute surely that's an invalid argument...
Probably going to write my own method to do what I want, just wanted to get everyone's opinion on why it could have been purposely designed like this.