【问题标题】:How to get a file path in visual studio 2013 solution explorer?如何在 Visual Studio 2013 解决方案资源管理器中获取文件路径?
【发布时间】:2015-12-14 08:11:34
【问题描述】:

我在数据文件夹下的解决方案资源管理器中有一个 .wav 文件。我需要通过 SoundPlayer 播放它。当我尝试通过“~/Data/xyz.wav”将文件放在声音位置时,它会出现一些运行时问题。如何修复文件路径?

我试过这段代码

SoundPlayer player = new SoundPlayer();
player.SoundLocation = "~/Data/spanish_guitar.wav";
player.Load();
player.PlaySync();

我在解决方案资源管理器中手动创建了 Data 文件夹。

【问题讨论】:

  • “它发生了一些运行时问题”?! +3!?说真的,今天 SO 发生了什么?

标签: c# filepath


【解决方案1】:

你可以尝试定义项目的路径并添加文件名

var projectPath = Path.GetDirectoryName(Path.GetDirectoryName(System.IO.Directory.GetCurrentDirectory()));
var filePath = Path.Combine(projectPath, "Data", "spanish_guitar.wav");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-13
    • 1970-01-01
    • 2014-03-10
    • 1970-01-01
    • 2012-11-24
    • 2015-10-25
    • 2019-04-23
    相关资源
    最近更新 更多