Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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
File C语言中的资源文件寻址#_File_C# 4.0_Resources_Addressing - Fatal编程技术网

File C语言中的资源文件寻址#

File C语言中的资源文件寻址#,file,c#-4.0,resources,addressing,File,C# 4.0,Resources,Addressing,我已通过右键单击->现有项将文件添加到资源中。 现在,我想将添加的文件复制到另一个目录中,如下所示: File.Copy(@“我不知道”,“C:\Users\user-1\Desktop\”,true) 我不知道我必须在@“我不知道”部分写些什么来寻址添加的资源文件。如果myDir是项目的目录,则资源文件的路径为myDir\Properties\resources.resx 现在,当您在调试模式下从Visual Studio执行程序时,文件夹为myDir\Bin\Debug 您必须进入2个文件夹

我已通过右键单击->现有项将文件添加到资源中。 现在,我想将添加的文件复制到另一个目录中,如下所示:

File.Copy(@“我不知道”,“C:\Users\user-1\Desktop\”,true)

我不知道我必须在@“我不知道”部分写些什么来寻址添加的资源文件。

如果myDir是项目的目录,则资源文件的路径为myDir\Properties\resources.resx

现在,当您在调试模式下从Visual Studio执行程序时,文件夹为myDir\Bin\Debug

您必须进入2个文件夹,然后进入Properties文件夹:

我建议您不要以硬编码方式使用路径分隔符(@“dir1\dir2…”)

var resourcesFileName = "Resources.resx";

var currentDirectory = Directory.GetCurrentDirectory();

var actualResourceFilePath = Path.Combine(
    currentDirectory, "..", "..", "Properties", resourcesFileName);

var desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

var newFilePath = Path.Combine(desktop, resourcesFileName);

File.Copy(actualResourceFilePath, newFilePath, true);