O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Working with Paths

In the previous examples, we’ve been dealing with user input to specify a path. If a path contains invalid characters, constructors like DirectoryInfo’s will throw an exception to signal such an issue.

Often, developers need to go beyond just taking a prepared path. While paths are just string values, manipulating them as such (for example, using plain old concatenation) isn’t a particularly good idea, especially when user input is involved. The chance of building an invalid path exists, so it’s better to let specialized functions do the job. For this purpose, the static methods on the Path class were introduced as wrappers around a set of APIs available in Win32.

One set of methods deals with breaking up a path in its constituents, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required