Skip to content

Instantly share code, notes, and snippets.

@Seich
Created November 13, 2011 01:55
Show Gist options
  • Save Seich/1361472 to your computer and use it in GitHub Desktop.
Save Seich/1361472 to your computer and use it in GitHub Desktop.
public static string MakeValidFileName( string name )
{
string invalidChars = Regex.Escape( new string( Path.GetInvalidFileNameChars() ) );
string invalidReStr = string.Format( @"[{0}]+", invalidChars );
return Regex.Replace( name, invalidReStr, "_" );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment