Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically building filepaths in .Net

Tags:

.net

vb.net

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.

like image 280
Simon Avatar asked Dec 14 '22 03:12

Simon


2 Answers

Use Path.Combine

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

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

like image 130
JaredPar Avatar answered Dec 16 '22 18:12

JaredPar


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

like image 38
Gishu Avatar answered Dec 16 '22 18:12

Gishu