Thursday 6 September 2007

Combining Paths

How many times have you written code to concatenate a file name to the end of a path? How many times has this failed because you either forgot to add the back slash or put in too many slashes?

The following code will do the check for the back slashes for you and append one if necessary:

Path.Combine(path1, path2)

This is particularly handy if the paths come from user input.

Nice! No more checking the last character of the string for a slash!

No comments: