文件名中存在非法字符

发布于 2024-09-02 06:23:54 字数 247 浏览 0 评论 0原文

在文件上传过程中,我发现表格中保存了非法字符。 zurück.pdfC _Word.doc 是文件名。这里üC_Word之间的空格在表格列中被发现为?。我通过用 _ (下划线)替换非字母数字值来验证客户端中的文件名,但它仍然会转义并保留到数据库中。这些如何在客户端处理?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

伴我老 2024-09-09 06:23:54

作为一个以德语为母语的人,我可以向您保证“ü”和“ ”都不是非法字符。

您的数据表使用哪种字符编码?您在客户端做什么来保证所有字符都在有效范围内?

如果您的数据库仅支持 ASCII 字符(并且无法更改),那么您应该使用 System.Text.ASCIIEncoding 将所有非 ASCII 字符替换为“?”为你。

更好的是,转义 Unicode 字符并以某种与 ASCII 字符集兼容的方式表示它们,例如,使用 '\u9404' 来表示 Unicode 字符 9404,请参阅 RFC5137 了解执行此操作的一些方法,并阅读 将 Unicode 字符串转换为转义的 ASCII 字符串

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.

木落 2024-09-09 06:23:54

我同意 Sebastian - 问题不在于这些文件名中存在非法字符,但它们对于您正在使用的数据库来说不是有效字符。假设数据库是 SQL Server,如果列数据类型当前是 char、varchar 或 text 之一,请尝试将列数据类型更改为 nchar、nvarchar 或 ntext。

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.

木有鱼丸 2024-09-09 06:23:54

您可以使用 CustomValidator 来调用 System.IO.Path.GetInvalidFileNameChars() 或将其结果转换为正则表达式,以便使用 RegulaExpressionValidator 进行客户端验证代码>.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文