软件编程
位置:首页>> 软件编程>> C#编程>> C#中文件名或文件路径非法字符判断方法

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

作者:junjie  发布时间:2023-12-01 14:14:21 

标签:C#,文件名,文件路径,非法字符判断

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


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

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com