Is there an easy way of dynamically building a filepath in .Net? At the moment I'm building the filepath by concatenating various strings (from application settings, user input and Date.ToString) but this relies on there not being double '\' characters or illegal characters etc in the strings. Obviously I can manually validate the strings for this sort of thing but I was wondering if there was something built into .Net that can handle this.
+3
A:
System.IO.Path.Combine()
This class has many members related to Path manipulation
Gishu
2009-07-01 13:37:25
+10
A:
Use Path.Combine
Dim p = Path.Combine(somePath, "foo\bar")
Documentation: http://msdn.microsoft.com/en-us/library/dd169357.aspx
JaredPar
2009-07-01 13:37:29
Preferably Path.Combine(Path.Combine(somePath, "foo"), "bar") IMO :) (Why isn't there an overload of Path.Combine which takes more strings? Please nag the BCL team for me :)
Jon Skeet
2009-07-01 13:41:22
I've wondered about that for a long time.
Kev
2009-07-01 13:45:20