Skip to content

Instantly share code, notes, and snippets.

@jaywick
Created June 30, 2015 05:26
Show Gist options
  • Select an option

  • Save jaywick/985034c2ccf55130b32f to your computer and use it in GitHub Desktop.

Select an option

Save jaywick/985034c2ccf55130b32f to your computer and use it in GitHub Desktop.
Return file name safe from illegal file system characters
static string MakeSafeFileName(string name, char replaceChar = '_')
{
var temp = name;
foreach (var character in Path.GetInvalidFileNameChars().Concat(Path.GetInvalidPathChars()))
{
temp = temp.Replace(character, replaceChar);
}
return temp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment