The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,087 other followers

Archive for November 13th, 2012

.NET/C#: Cleaning up path names with invalid characters (via: validation – C# Sanitize File Name – Stack Overflow)

Posted by jpluimers on 2012/11/13

Thanks Andre for this cleanup code:

To clean up a file name you could do this

private static string MakeValidFileName(string name)
{
string invalidChars = Regex.Escape( new string( Path.GetInvalidFileNameChars() ) );
string invalidReStr = string.Format( @"[{0}]+", invalidChars );
return Regex.Replace( name, invalidReStr, "_" );
}

Next to GetInvalidFileNameChars, you have GetInvalidPathChars.

–jeroen

via: validation – C# Sanitize File Name – Stack Overflow.

Posted in .NET, C#, Development, Software Development | 2 Comments »

 
%d bloggers like this: