On a asp.net web site, a user tried to upload a file as an email attachment that contained an emdash in the file name. When sending this as an email attachment (exchange server) the file got converted to _utf8_B_****.dat
So, on a .aspx page, I need to be able to detect if an emdash is present in the filename of a file that is uploaded as part of the Request.Files collection.
string s = "a—b-";
byte[] arr = Encoding.ASCII.GetBytes(s);
foreach (byte element in arr)
{
Response.Write(element.ToString() + ",");
}
The string above has an emdash as the second character and a normal hyphen as the fourth character.
The code above prints 97,63,97,45 to the screen.
I assumed that as an emdash is not a valid ASCII character, either an error would be thrown or some indication shown that it was not a valid ASCII character. Yet it returns 63.
How can I detect an emdash in a file name so I can say to the user 'Your file name has an invalid character in it'? I have seen other questions on this issue, I can't get them to work.