4

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.

1
  • 3
    +1 for asking about this instead of just sticking with the manual path assembling method, like so many poeple do. Commented Jul 1, 2009 at 13:44

2 Answers 2

10

Use Path.Combine

Dim p = Path.Combine(somePath, "foo\bar")

Documentation: http://msdn.microsoft.com/en-us/library/dd169357.aspx

Sign up to request clarification or add additional context in comments.

1 Comment

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 :)
3

System.IO.Path.Combine()
This class has many members related to Path manipulation

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.