Skip to content

Instantly share code, notes, and snippets.

@JeffreyMFarley
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeffreyMFarley/dbad21c250103bce426f to your computer and use it in GitHub Desktop.
Save JeffreyMFarley/dbad21c250103bce426f to your computer and use it in GitHub Desktop.
Remove Bad File Name Characters
static public string RemoveBadFileNameChars(this string strFileName)
{
char[] badPath = Path.GetInvalidPathChars();
char[] badFile = { '\\', '/', ':', '*', '?', '\"', '<', '>', '|', '' };
foreach (char c in badPath)
strFileName = strFileName.Replace(c, '_');
foreach (char c in badFile)
strFileName = strFileName.Replace(c, '_');
strFileName = strFileName.Replace("\0", "");
return strFileName;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment