So I came up with this:
public static Filename buildValidFilename(str _filename)
{
#xppTexts
#define.LeftSquareBracket('[')
#define.RightSquareBracket(']')
Filename validFilename;
str invalidFileNameChars;
new InteropPermission(InteropKind::ClrInterop).assert();
// Remove the characters that .NET defines as invalid
invalidFileNameChars = new System.String(System.IO.Path::GetInvalidFileNameChars());
validFilename = System.Text.RegularExpressions.Regex::Replace(_filename, #LeftSquareBracket + invalidFileNameChars + #RightSquareBracket, #emptyString);
// Remove the characters that .NET doesn't remove
invalidFileNameChars = @'"\\/:*?\<>|' + "'";
validFilename = System.Text.RegularExpressions.Regex::Replace(validFilename, #LeftSquareBracket + invalidFileNameChars + #RightSquareBracket, #emptyString);
CodeAccessPermission::revertAssert();
return validFilename;
}
*This post is locked for comments