Art wrote:
i want to use strings as filenames that include characters that are
not allowed in windows filenames. is there a special converter method
for this? something like HttpUtility.UrlEncode(...) for Urls.
if not, what characters do i have to replace? is there an encoding
that is valid? i could create a byte[] from the utf8-string and encode
it into a <whatever encoding is valid for windows filenames>-string.
I am not aware of anything particular.
You can make something up.
One suggestion:
public static string SafeName(string fnm)
{
string res = fnm;
MatchCollection reg = Regex.Matches(res, @"[^A-Za-z0-9-_\.]");
for(int i = 0; i < reg.Count; i++) {
res = res.Replace(reg[i].Groups[0].Value, "__" +
((int)reg[i].Groups[0].Value[0]).ToString("X2"));
}
return res;
}
Arne