Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 31
    string strTheseAreInvalidFileNameChars = new string( System.IO.Path.GetInvalidFileNameChars() ) ; Regex regFixFileName = new Regex("[" + Regex.Escape(strTheseAreInvalidFileNameChars ) + "]"); Commented Oct 19, 2010 at 14:36
  • 2
    A little research from people would work wonders. I've updated the post to reflect the changes. Commented Dec 22, 2013 at 6:03
  • 1
    2nd piece of code doesn't compile. "Cannot convert from char[] to string Commented Apr 25, 2014 at 12:03
  • 1
    +1 for the code, but please replace Path.GetInvalidPathChars() with Path.GetInvalidFileNameChars() as Path.GetInvalidPathChars() is obsolete now Commented Nov 2, 2017 at 8:44
  • 1
    @AshkanMobayenKhiabani: InvalidPathChars is obsolete but GetInvalidPathChars does not. Commented Mar 31, 2020 at 13:27