Hmmm... you're quite right, Aidan. It is indeed my mistake for not
checking the code and posting an ad-hoc solution. I was relying on my
memory of a similar situation.

To clarify, Path.GetFullPath() does not return the same string in
response to the values supplied in our example (It appears that the
trailing slash is a common source of problems for most developers). I
think that Subrato's solution would be the best bet which uses the
same principle but creates a DirectoryInfo object and retrieves the
full path back from that instance. The precondition however is that
your directory should exist.

If that precondition is not acceptable in your scenario, then the only
option I can think of is to check the input string for a trailing
slash. (I know, that's a pathetic way) ;-)

On Dec 23, 1:04 pm, Aidan Whitehall <[email protected]> wrote:
> @Cerebrus
>
> On Dec 21, 10:49 am, Cerebrus <[email protected]> wrote:
>
> > This very problem is commonly referred to in IT Security parlance as a
> > "Canonicalization" problem. The problem arises from the fact that the
> > [snip]
> > string p1 = Path.GetFullPath(txtPath1.Text);
> > string p2 = Path.GetFullPath(txtPath2.Text);
> > [snip]
>
> Doing this
>
>   using System.IO;
>   MessageBox.Show(Path.GetFullPath("C:\Temp\Source"));
>   MessageBox.Show(Path.GetFullPath("C:\Temp\Source\"));
>
> displays two different values.
>
> In addition, using your code in amongst the code for the form displays
> "Different".
>
> Are you sure GetFullPath() works as you thought?
>
> Thanks again for your help.

Reply via email to