ValidateFileName.cs This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters private static string MakeValidFileName ( string name , char replaceChar ) { string str_replaceChar = "" + replaceChar ; string invalidChars = System . Text . RegularExpressions . Regex . Escape ( new string ( System . IO . Path . GetInvalidFileNameChars ( ) ) ) ; string invalidRegStr = string . Format ( @"([{0}]*.+$)|([{0}]+)" , invalidChars ) ; return System . Text . RegularExpressions . Regex . Replace ( name , invalidRegStr , str_replaceChar ) ; }