title: Why illegal characters in path?
body: <pre><code>....
  case "DOWNLOAD":
  if (File.Exists(commandContent)) {
  MessageBox.Show(commandContent);
  result = System.Convert.ToBase64String(File.ReadAllBytes(commandContent)); //ERROR
  result = HttpUtility.UrlEncode(result);          
  }
  break;
  </code></pre>
  
  <p>And Unhandled Error exception says "illegal characters" in path. The MessageBox shows a correct path </p>
  
  <pre><code>  C:\Users\Me\Myfile.exe
  </code></pre>
  
  <p>I tried to do the following :</p>
  
  <pre><code> commandContent = commandContent.replace(@"\",@"\\");
   result = System.Convert.ToBase64String(File.ReadAllBytes(commandContent)); //ERROR
  </code></pre>
  
  <p>I also tried the following :</p>
  
  <pre><code> commandContent = @""+commandContent+"";
   result = System.Convert.ToBase64String(File.ReadAllBytes(commandContent)); //ERROR
  </code></pre>
  
  <p>but this doesn't work. And the more strange is that it was working correctly as it is, but once I made some modification in the way I'm inserting commandContent into db (using ajax instead of regular form submit), this problem appears ?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I tried to hard code the path using </p>
  
  <pre><code> commandContent = @"C:\Users\Me\file.exe";
  </code></pre>
  
  <p>That worked correctly. How can I force the variable not to contain any illegal characters?</p>