简体   繁体   English

如何在visual studio 2013解决方案资源管理器中获取文件路径?

[英]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.

相关问题 Visual Studio 2013扩展解决方案资源管理器筛选器 - Visual Studio 2013 Extending Solution Explorer Filter 如何在运行时将 c# 文件添加到 Visual Studio 解决方案资源管理器? - How to add a c# file to Visual Studio Solution Explorer at runtime? Visual Studio C#2013 Express的解决方案资源管理器 - Solution Explorer for Visual Studio C# 2013 Express 是否可以在Visual Studio 2013的解决方案资源管理器中手动标记文件 - Is it possible to manually flag files in the Solution Explorer in Visual Studio 2013 解决方案资源管理器中的 Visual Studio 2017 锁定文件 - Visual Studio 2017 lock file in solution explorer 配置文件未出现在 Visual Studio 的解决方案资源管理器中 - Config file not appearing in solution explorer in visual studio 如何通过Visual Studio插件获取Visual Studio Project(在解决方案资源管理器中加载)的位置? - How to get Visual Studio Project (which is loaded in solution explorer) location via a Visual Studio Addin? 如何在Visual Studio中使用C#在解决方案中轻松获取文件夹内文件的路径? - How can I easily get the path of a file inside a folder in my solution in Visual Studio with C#? 我无法使用与目录相同的名称将项目加载到Visual Studio 2013中,也无法在解决方案资源管理器中重命名项目 - I cannot get projects to load into Visual Studio 2013 with the same name as their directory and I cannot rename the projects in Solution Explorer Visual Studio扩展:如何在选择时获取解决方案文件夹的“路径”? - Visual Studio Extension: How to get the “path” of a solution folder on selection?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM