title: How do I check for illegal characters in a path?
body: <p>Is there a way to check if a String meant for a path has invalid characters, in .Net? I know I could iterate over each character in Path.InvalidPathChars to see if my String contained one, but I'd prefer a simple, perhaps more formal, solution.</p>
  
  <p>Is there one?</p>
  
  <p>I've found I still get an exception if I only check against Get</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I've found GetInvalidPathChars does not cover every invalid path character. GetInvalidFileNameChars has 5 more, including '?', which I've come across. I'm going to switch to that, and I'll report back if it, too, proves to be inadequate.</p>
  
  <p><strong>Update 2:</strong></p>
  
  <p>GetInvalidFileNameChars is definitely not what I want. It contains ':', which any absolute path is going to contain ("C:\whatever"). I think I'm just going to have to use GetInvalidPathChars after all, and add in '?' and any other characters that cause me problems as they come up. Better solutions welcome.</p>