C#中文件名或文件路径非法字符判断方法
文件路径或者保存模板出现非法字符判断
1)不为空判断
stringstrTemplateName=txtTemplateName.Text; if(string.IsNullOrWhiteSpace(strTemplateName)) { Show("请输入模板名称!","提示",.Information,OK); txtTemplateName.Focus(); return; }
2)然后对strTemplateName进行非法字符判断
if(strTemplateName.IndexOfAny(Path.GetInvalidFileNameChars())>=0) { //含有非法字符\/:*?"<>|等 Show("模板名称含有非法字符,请重新输入","错误",Error,OK); txtTemplateName.Focus(); return; }
3)path引用系统的io动态库即可。