0

I've added my file into resources with right click -> existing item. Now I want to copy the added file into another directory like this:

File.Copy(@"I don't know", @"C:\Users\user-1\Desktop\", true);

I don't know what I have to write in @"I don't know" part to addressing the added resource file.

Leviathan
  • 31
  • 1
  • 9

1 Answers1

0

If myDir is the directory of your project, the resources' file has path myDir\Properties\Resources.resx.

Now, when you execute a program from Visual Studio in Debug mode, the folder is myDir\Bin\Debug.

You have to go up 2 folders and enter the Properties folder:

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

I suggest you to not use the path separator in the hard-coded way (@"dir1\dir2...").

Use Path.Combine instead.

Community
  • 1
  • 1
Massimiliano Kraus
  • 3,638
  • 5
  • 27
  • 47