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);