I am working on a media player in C# but when I want to make my test I have a problem.
I have to create a new object song with the following path:
@"C:\Users\Jesus Antonio\Desktop\JukeboxV2.0\JukeboxV2.0\Datos\ich will.mp3"
You would do something like this to get the path "Data\ich_will.mp3" inside your application environments folder.
string fileName = "ich_will.mp3"; string path = Path.Combine(Environment.CurrentDirectory, @"Data\", fileName);
In my case it would return the following:
Environment.CurrentDirectory in my example. These are very useful and allows you to build a path based on the current location of your application.
Path.Combine combines two or more strings to create a location, and
Environment.CurrentDirectory provides you with the working directory of your application.
The working directory is not necessarily the same path as where your
executable is located, but in most cases it should be, unless specified otherwise.