Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过单击一次发布应用程序后visual studio中文件的路径_C#_Windows_Visual Studio_Winforms_Share - Fatal编程技术网

C# 通过单击一次发布应用程序后visual studio中文件的路径

C# 通过单击一次发布应用程序后visual studio中文件的路径,c#,windows,visual-studio,winforms,share,C#,Windows,Visual Studio,Winforms,Share,我想把我的应用程序发布给我的朋友,让他们的安装尽可能简单,这样我的应用程序就可以使用SoundPlayer,它需要文件来播放声音。我的问题是我如何知道他们将把这个文件保存在哪里 我使用了以下代码: SoundPlayer music = new SoundPlayer(ApplicationDeployment.CurrentDeployment.DataDirectory + @"\songfolder\Main.wav"); 这给了我一个错误:应用程序标识未设置 PS:

我想把我的应用程序发布给我的朋友,让他们的安装尽可能简单,这样我的应用程序就可以使用SoundPlayer,它需要文件来播放声音。我的问题是我如何知道他们将把这个文件保存在哪里

我使用了以下代码:

SoundPlayer music = new SoundPlayer(ApplicationDeployment.CurrentDeployment.DataDirectory + @"\songfolder\Main.wav");
这给了我一个错误:应用程序标识未设置


PS:抱歉我的英语不好:D

你是说通过ClickOnce发布项目吗?您可以转到
Project->Properties->Publish
,检查所需文件是否包含在
应用程序文件中

解决方案资源管理器:

应用程序文件:

您需要使用以下代码来访问这些文件

string filepath = AppDomain.CurrentDomain.BaseDirectory + @"songfolder\song.mp3";

最后,单击
Publish Now
将其发布。

我编写的代码如下:
SoundPlayer music=new SoundPlayer(AppDomain.CurrentDomain.BaseDirectory+@“songfolder\Menu.wav”)它告诉我没有找到错误文件,你知道问题出在哪里吗?如果没有,谢谢@Magma是否已将发布状态设置为
数据文件
?@Magma或尝试此
ApplicationDeployment.CurrentDeployment.DataDirectory+@“songfolder\song.mp3”
以获取文件路径。是的,我将其设置为
数据文件
,甚至尝试了第二个代码,但仍然相同error@Magma很奇怪。安装应用程序后,检查文件是否包含在
C:\Users\username\AppData\Local\Apps\2.0\Data
的子文件夹中。