Skip to content

Instantly share code, notes, and snippets.

@raducugheorghe
raducugheorghe / Sanitize folder name
Created December 9, 2014 12:51
[C#] Sanitize string to use as folder name
public static string SanitizeFolderName(string name)
{
string regexSearch = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());
var r = new Regex(string.Format("[{0}]", Regex.Escape(regexSearch)));
return r.Replace(name, "");
}