Illegal characters in path error

I am working on a project allows user to upload files to server and download uploaded files from server. It is simple and straight-forward: the file is save in file system, and the file path is saved in database. When user requests to download a file, the file path is returned from the database and user is prompted with the save file dialog to save the file. Everything has been working well, then suddenly one day the application threw a System.ArgumentException error saying “Illegal characters in path”. I checked the file system but didn’t find any illegal characters in any file names, so the problem is not in the file system. After more investigation, I found out the problem lies in the file path stored in database.

The data type for the file path column in database is varchar and doesn’t support Unicode text, so when a file that containing Unicode text in the file name is uploaded, the Unicode text becomes questions marks (?????), and when this file is requested for download, the question marks will cause the “Illegal characters in path” error. The fix is simple: change the data type from varchar to nvarchar to support Unicode text.

Leave a Reply

avatar
  Subscribe  
Notify of