Path.Combine
uses the values of Path.DirectorySeperatorChar
and Path.VolumeSeparatorChar
, and these are determined by the class libraries in the runtime - so if you write your code using only Path.Combine
calls, Environment.SpecialFolder
values, and so forth, it will run fine everywhere, since Mono (and presumably any .NET runtime) implements the native way of getting and building those paths for any platform it runs on. (Your second example, for instance, returns /server/mydir
for me, but the first example gives c:\/windows
)
If you want a UNIX-specific path hard-coded in all cases, Path.Combine
isn't buying you anything: Console.WriteLine ("/server/mydir");
does what you want in the OP.
As Hans said though, different filesystems have different rules for allowed characters, path lengths, and etc., so the best practice, like with any cross-platform programming, is to restrict yourself to using the intersection of allowed features between the filesystems you're targeting. Watch case-sensitivity issues too.