title: C# - Illegal characters in path
body: <p>I have a database table that containing file paths of excel files that I import using a C# script.</p>
  
  <p>The script works fine unless the filepath contains spaces e.g. <code>C:\Temp\My Excel File.xls</code> and I get an <code>Illegal characters in path</code> error message. Unfortunately I am not able to change the file names at the source.</p>
  
  <p>If I hard code the file path to be as below it works fine.</p>
  
  <pre><code>String Filepath = @"C:\Temp\My Excel File.xls";
  </code></pre>
  
  <p>How do I alter this so I can include a string variable that will store the filepath from the database e.g.</p>
  
  <pre><code>String Filepath = //Code to get FilePath from database
  
  StringCorrectedFilePath = @+FilePath;
  </code></pre>
  
  <p>Thanks in advance of any help</p>
  
  <p><strong>Edit</strong>: Issue is caused by files that start with a number creating invalid escape sequence. e.g. <code>C:\Temp\20160611 My Excel File.xls</code></p>
  
  <p><strong>Edit 2</strong>: SOLVED - Error was caused by carriage return characters appearing after the file extension. Please see my answer for the solution.</p>