2
string app_path_temp = App.App_Path + "\\";

string sourcePath = System.IO.Path.Combine(app_path_temp, "Dump\\SID\\temp\\", filename1);

string destPath = System.IO.Path.Combine(app_path_temp, "Training\\", fileBaseName, "\\", filename1);

File.Copy(sourcePath, destPath, true);

When I give set the folder path as "FolderName1\FolderName2\FolderName3\ApplicationPath", the code works just fine. However when the path is like "Folder Name 1\Folder Name 2..." it doesn't work.

Shows an error "Could not find file at Folder Name 1\Folder Name 2..."

DevSenGoku
  • 75
  • 1
  • 11
  • Please refer [handle-spaces-in-file-path](https://stackoverflow.com/questions/6521546/how-to-handle-spaces-in-file-path-if-the-folder-contains-the-space) – abdul-wahab Feb 14 '18 at 08:48
  • the Application Path is implicitly set using the `string app_path_temp = App.App_Path + "\\";` How can I add double quotations to `App.App_Path`? – DevSenGoku Feb 14 '18 at 08:49
  • try to investigate first by using `Directory.Exists` – Vijunav Vastivch Feb 14 '18 at 08:52
  • @DebaleenSenguptaVehere to add double quotes to an item, you use double quotes such as "Sally says ""this is a test"" rather quietly" – BugFinder Feb 14 '18 at 08:54
  • @BugFinder So, you mean **"**App.App_Path**"** when it is assigned to `string app_path_temp`? – DevSenGoku Feb 14 '18 at 08:59
  • @abdul-wahab that link doesn't explain the case when I want to get the file path at runtime. `App.App_Path` gives me the Folder Path at runtime. – DevSenGoku Feb 14 '18 at 09:02
  • Take out "\\" in Path.Combine because it will add this for you i.e. change string destPath = System.IO.Path.Combine(app_path_temp, "Training\\", fileBaseName, "\\", filename1); to string destPath = System.IO.Path.Combine(app_path_temp, "Training", fileBaseName, filename1); – majita Feb 14 '18 at 09:05

1 Answers1

1

In C# 6, you can apply both $ and @ prefixes to the same string, it means "Interpolate this verbatim string", hope this work for you:

string sourcePath = $@"{App.App_Path}\Dump\SID\temp";
string destPath = $@"{App.App_Path}\Training\{fileBaseName}";

// Use Path class to manipulate file and directory paths.
string sourceFile = System.IO.Path.Combine(sourcePath, filename1);
string destFile = System.IO.Path.Combine(destPath, filename1);

File.Copy(sourceFile, destFile, true);
maxchiu
  • 146
  • 1
  • 5