如何安全地保存文件到硬盘没有风险的窗户拒绝它? [英] How to safely save file to disk without the risk of windows reject it?

查看:170
本文介绍了如何安全地保存文件到硬盘没有风险的窗户拒绝它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个WinForm应用程序。我想利用用户输入(即用户提供用户名),并使用该输入作为文件名的一部分,并保存到文件。

I'm developing a winform application. I want to take input from user (i.e. the user provides username) and use that input as part of filename and save to file.

我如何检查,如果用户提供的用户名不包含Windows的保留字符。什么是保留字符的窗口列表?

How do I check if the username provided by the user didn't contain windows' reserved characters. And what is the list of reserved characters for windows?

推荐答案

通过:

    Path.GetInvalidFileNameChars()

    Path.GetInvalidPathChars()

确切名单的可以的特定于平台(尤其是单声道),它包括一些非打印字符...所以在这里向您展示他们是棘手; P

The exact list could be platform-specific (especially for mono), and it includes some non-printable characters... so showing you them here is tricky ;p

这篇关于如何安全地保存文件到硬盘没有风险的窗户拒绝它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆