What is the equivalent to PathCanonicalize in C#?
Use: I need to take a good guess whether two file paths refer to the same file (without disk access). My typical approach has been throwing it through a few filters like MakeAbsolute and PathCanonicalize, and then do a case-insensitive comparison.
quick and dirty:
In the past I have created a FileInfo object from the path string and then used the FullName property. This removes all of the ..\'s and the .\'s.
Of course you could interop:
3 solutions:
Best case scenario, where you are 100% certain the calling process will have full access to the filesystem. CAVEAT: permission on a production box can be tricky
But, we're not always free. Often you need to do the string arithmetic without permission. There is a native call for this. CAVEAT: resorts to native call
A third strategy is to trick the CLR. Path.GetFullPath() works just fine on a fictitious path, so just make sure you're always giving it one. What you can do is to swap out the root with a phony UNC path, call GetFullPath(), and then swap the real one back in. CAVEAT: this may require a hard sell in code review