title: Remove invalid (disallowed, bad) characters from FileName (or Directory, Folder, File)
body: <p>I've wrote this little method to achieve the goal in the subj., however, is there more efficient (simpler) way of doing this? I hope this can help somebody who will search for this like I did.</p>
  
  <pre><code>var fileName = new System.Text.StringBuilder();
  fileName.Append("*Bad/\ :, Filename,? ");
  // get rid of invalid chars
  while (fileName.ToString().IndexOfAny(System.IO.Path.GetInvalidFileNameChars()) &gt; -1)
  {
      fileName = fileName.Remove(fileName.ToString().IndexOfAny(System.IO.Path.GetInvalidFileNameChars()), 1);
  }
  </code></pre>
  
  <p>?</p>