private static string GetCleanID(string path, int limit, bool replaceDot = false, bool removeDot = false, bool replaceDirectorySeparatorChar = false, bool removeDirectorySeparatorChar = false, bool replaceSpaces = false, bool removeSpaces = false, bool removeUnderscores = false) { if (replaceDot) path = path.Replace('.', '_'); if (removeDot) path = path.Replace(".", ""); if (replaceDirectorySeparatorChar) path = path.Replace(Path.DirectorySeparatorChar, '_'); if (removeDirectorySeparatorChar) path = path.Replace(Path.DirectorySeparatorChar.ToString(), ""); if (replaceSpaces) path = path.ReplaceWhiteSpace('_'); if (removeSpaces || !replaceSpaces) path = path.RemoveWhiteSpace(); path = new Regex("[^a-zA-Z0-9_.]").Replace(path, "_"); path = path.RemoveDuplicates("_").TrimEnd('_').TrimStart('_'); if (removeUnderscores) path = path.Replace("_", ""); if (path.Length > limit) { byte[] nameBytes = Encoding.Default.GetBytes(path); uint crc = nameBytes.Crc32Checksum(0, nameBytes.Length); string suffix = crc.ToString(); path = path.Substring(0, limit - suffix.Length) + suffix; } return path; }