Craig has a snippet for building paths
I often see people using string concatenation to create directory names. Like this:
string path = "C:\\data\\" + filename;
But there's a much better API:
string path = System.IO.Path.Combine("C:\\data", filename);
Not only does this take care of the whole, "Do I need a trailing slash?" issue, but if you specify an absolute path for the second parameter, it will just return the second parameter. That means that someone can enter "foo" or "C:\\temp\\foo" for filename, and it'll do what you'd expect.
[Craig Andera]
6:04:07 PM
|