[英]How to get a file path in visual studio 2013 solution explorer?
I have a .wav file in solution explorer under Data folder. 我在Data文件夹下的解决方案资源管理器中有一个.wav文件。 I need to play it via SoundPlayer.
我需要通过SoundPlayer播放它。 When i try to get the file in sound location by "~/Data/xyz.wav" it occours some runtime problem.
当我试图通过“〜/ Data / xyz.wav”获取声音位置的文件时,它会出现一些运行时问题。 How to fix the file path?
如何修复文件路径?
I tried through this code 我试过这段代码
SoundPlayer player = new SoundPlayer();
player.SoundLocation = "~/Data/spanish_guitar.wav";
player.Load();
player.PlaySync();
Manually I created the Data folder in Solution Explorer. 手动我在解决方案资源管理器中创建了Data文件夹。
You can try to define the path of project and add file name 您可以尝试定义项目的路径并添加文件名
var projectPath = Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()));
var filePath = Path.Combine(projectPath, "Data", "spanish_guitar.wav");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.