This article mainly introduced the C # Chinese part name or the file path illegal character judgment method, this article mainly uses the built-in Getinvalidfilenamechars method to realize the illegal character judgment, needs the friend may refer to under
File path or save template illegal character judgment
1) NOT NULL judgment
?
1 2 3 4 5 6 7 |
string strtemplatename = Txttemplatename.text; if (string. Isnullorwhitespace (Strtemplatename)) {Show (Please enter the template name!) "," prompted, ". information, OK); Txttemplatename.focus (); Return } |
2) and then to strtemplatename the illegal character judgment
?
1 2 3 4 5 6 7 |
if (Strtemplatename.indexofany (Path.getinvalidfilenamechars ()) >= 0) {//contains illegal characters/: *? "< > | Wait for show ("template name contains illegal characters, please re-enter", "error", errors, OK); Txttemplatename.focus (); Return } |
3 The path refers to the system's IO dynamic library.