如何使用双 (.) (.)“fileName ..pdf”验证安全文件名

发布于 2024-09-25 00:36:15 字数 456 浏览 0 评论 0原文

我正在搜索如何在我的网络应用程序中创建一个安全的文件名,我在这里阅读了很多帖子,最后一篇 如何检查给定的字符串在 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 技术交流群。

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

发布评论

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

评论(1

吹泡泡o 2024-10-02 00:36:15

之后我会进行额外的检查,并将 .. 替换为 .

foreach (var c in Path.GetInvalidFileNameChars())
    fileName = fileName.Replace(c, '-');

fileName = fileName.Replace("..", ".");

I would do an extra check afterwards and replace the .. with .:

foreach (var c in Path.GetInvalidFileNameChars())
    fileName = fileName.Replace(c, '-');

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