Skip to content

Instantly share code, notes, and snippets.

@sondreb
Created March 28, 2014 10:03
Show Gist options
  • Save sondreb/9829299 to your computer and use it in GitHub Desktop.
Save sondreb/9829299 to your computer and use it in GitHub Desktop.
One-liner that sanitizes the file name. Remember: There is a different method to get invalid path chars.
// Remove any invalid file name characters that might have been added to the name.
var newName = string.Join("_", fileName.Split(Path.GetInvalidFileNameChars(), StringSplitOptions.RemoveEmptyEntries)).TrimEnd('.');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment