To Remove Illegal Filename Characters in C# and VB.NET you can use the following snippet.
Sample C#
public static string RemoveIllegalFileNameChars(string input, string replacement="")
{
var regexSearch = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());
var r = new Regex(string.Format("[{0}]", Regex.Escape(regexSearch)));
return r.Replace(input, replacement);
}
Sample VB.NET
Public Shared Function RemoveIllegalFileNameChars(input As String, Optional replacement As String = "") As String
Dim regexSearch = New String(Path.GetInvalidFileNameChars()) & New String(Path.GetInvalidPathChars())
Dim r = New Regex(String.Format("[{0}]", Regex.Escape(regexSearch)))
Return r.Replace(input, replacement)
End Function
emove Illegal Filename Characters in C# and #VB .NET http://t.co/v0QZAVww66 #dotnet #csharp #programming #code #coding #dev #developer
RT @CodeSnippetsNET: emove Illegal Filename Characters in C# and #VB .NET http://t.co/v0QZAVww66 #dotnet #csharp #programming #code #coding…
RT @CodeSnippetsNET: emove Illegal Filename Characters in C# and #VB .NET http://t.co/v0QZAVww66 #dotnet #csharp #programming #code #coding…
RT @CodeSnippetsNET: emove Illegal Filename Characters in C# and #VB .NET http://t.co/v0QZAVww66 #dotnet #csharp #programming #code #coding…