如何使用双 (.) (.)“fileName ..pdf”验证安全文件名
我正在搜索如何在我的网络应用程序中创建一个安全的文件名,我在这里阅读了很多帖子,最后一篇 如何检查给定的字符串在 Windows 下是否是合法/有效的文件名? 但当文件名时我找不到此示例的解决方案以“fileName ..pdf”(双点)的方式出现,浏览器至少无法在 IE 中打开该文件,并且至少对于 Windows 来说是一个安全的文件名,那么我如何搜索此异常并删除双点,我现在拥有的是以下示例(显然没有删除双点:
foreach (var c in Path.GetInvalidFileNameChars()) { fileName = fileName.Replace(c, '-'); }
Im sarching how to create a safe filename in my webapplication I had read a lot of post around here last one How do I check if a given string is a legal / valid file name under Windows? but I can't find the solution for this example when the filename comes in the way "fileName ..pdf" (double dot), the browser can't open the file at least IE and is a safe filename at least for windows,so how can I search for this exception and remove the double dot, what I have by now is the following example (which obviously doesn't remove the double dot:
foreach (var c in Path.GetInvalidFileNameChars()) { fileName = fileName.Replace(c, '-'); }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
之后我会进行额外的检查,并将
..
替换为.
:I would do an extra check afterwards and replace the
..
with.
: