Removing bad Characters in Windows Filenames using C#

 hi everyone, how are you ?
Removing characters in Windows filenames using C#

i hope that all your works going fine..
so, i want to share a little c# fonctions with you in this post :)
in the fact there are no exist method do that (as i know :D )

bu we will do that very simple with a regex:
//c# code:
Regex illegalInFileName = new Regex(@"[\\/:*?""<>|]");
string myString = illegalInFileName.Replace(myString, "");


 private Regex illegalInFileName = new Regex(string.Format("[{0}]", Regex.Escape(new string(Path.GetInvalidFileNameChars()))), RegexOptions.Compiled);
 string myString = @"A\\B/C:D?E*F""G<H>I|";
 myString = illegalInFileName.Replace(myString, "");

good look :)
By Drupal Study