C # String Filepath Question

I am trying to set the file path for an object SoundPlayer

If I have a folder with sounds in my main project folder. How do I send a message

Soundplayer test = new Soundplayer("Sounds/Fireball.wav");
+3
source share
3 answers

If the file regarding your main project is not important. What matters is where will the sound file be relative to your application during deployment / debugging. If it will have the same relative path as the main .exe path, you can use the following.

var root = typeof(Program).Assembly.Location;
var soundPath = Path.Combine(root, @"sounds\Fireball.wav");
var test = new SoundPlayer(soundPath);
+6
source

Have you tried the way how @"Sounds\Fireball.wav"?

+1
source

Visual Studio, bin\Debug, bin\Debug\Sounds\Fireball.wav.

, , \, forwardlash /

+1

Source: https://habr.com/ru/post/1780096/


All Articles