开发者

C# String Filepath Question

开发者 https://www.devze.com 2023-01-30 15:00 出处:网络
I am trying to set a filep开发者_如何学Pythonath for a SoundPlayer object If I have a sounds folder in my main project folder. How do I go about sending

I am trying to set a filep开发者_如何学Pythonath 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");


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);


Have you tried the path as @"Sounds\Fireball.wav"?


If you are running out of Visual Studio, the current working directory will be bin\Debug, so the file in question would need to be in bin\Debug\Sounds\Fireball.wav.

Also, as others have mentioned, you should use backslash \ rather than forwardslash /

0

精彩评论

暂无评论...
验证码 换一张
取 消