Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# String Filepath Question

Tags:

c#

I am trying to set a filepath for a SoundPlayer object

If I have a sounds folder in my main project folder. How do I go about sending

Soundplayer test = new Soundplayer("Sounds/Fireball.wav");
like image 209
RoR Avatar asked May 27 '26 00:05

RoR


1 Answers

Where the file is relative to your main project is not important. What's important is where will the sound file be relative to your application at deployment / debug time. If it will have the same relative path as that of the main .exe path then you can use the following.

var root = typeof(Program).Assembly.Location;
var soundPath = Path.Combine(root, @"sounds\Fireball.wav");
var test = new SoundPlayer(soundPath);
like image 113
JaredPar Avatar answered May 28 '26 14:05

JaredPar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!