信息发布→ 登录 注册 退出

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

发布时间:2026-01-11

点击量:

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


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

在线客服
服务热线

服务热线

4008888355

微信咨询
二维码
返回顶部
×二维码

截屏,微信识别二维码

打开微信

微信号已复制,请打开微信添加咨询详情!