问题
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.
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?
回答1:
via:
Path.GetInvalidFileNameChars()
and
Path.GetInvalidPathChars()
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
来源:https://stackoverflow.com/questions/6544851/how-to-safely-save-file-to-disk-without-the-risk-of-windows-reject-it