views:

313

answers:

3

Hi,

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 the 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?

A: 

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.

UserControl
+2  A: 

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 http://stackoverflow.com/questions/1615559/converting-unicode-strings-to-escaped-ascii-string.

Sebastian
+1  A: 

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.

Sean Reilly