Friday, August 26, 2011

C# function to clean file name

private string CleanFileName(string fileName)
{
string regexSearch =
new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());
Regex r = new Regex(String.Format("[{0}]", Regex.Escape(regexSearch)));
return r.Replace(fileName, "");
}

No comments:

Post a Comment