开发者

Illegal Character in File Name

During my file upload process, I found illegal character getting saved in Table. zurück.pdf, C _Word.doc were the file names. Here ü, space between C and _Word was found as ? in the Table Column. I have validate th开发者_Go百科e filename in client side by replacing non-alpha numeric values by _ (underscore), but still it escapes and persist into DB. How can these handled in Client side?


As a native german speaker, I can assure you that neither 'ü' nor ' ' are illegal characters.

Which character encoding does your data table use and what do you do on the client side to guarantee that all characters fall into the valid range?

If your database supports only ASCII characters (and cannot be changed), then you should be using System.Text.ASCIIEncoding which replaces all non-ASCII characters with '?' for you.

Better yet, escape the Unicode characters and represent them in some way that is compatible with the ASCII character set, e.g., use '\u9404', to represent Unicode character 9404, see RFC5137 for some methods of doing this and read the answers to Convert a Unicode string to an escaped ASCII string.


I agree with Sebastian -- the problem isn't that these are illegal characters for a file name, but that they aren't valid characters for the database you are using. Assuming that the database is SQL Server, try changing the column datatype to nchar, nvarchar or ntext if it's currently one of char, varchar, or text.


You can use CustomValidator with a call to System.IO.Path.GetInvalidFileNameChars() or convert its result to regex to have client-side validation with RegulaExpressionValidator.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜