当前位置: 移动技术网 > IT编程>开发语言>c# > C#中文件名或文件路径非法字符判断方法

C#中文件名或文件路径非法字符判断方法

2019年07月18日  | 移动技术网IT编程  | 我要评论

文件路径或者保存模板出现非法字符判断


1)不为空判断

string strtemplatename = 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 动态库即可。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网