如何检查路径是否有效? [英] how to check if the path is valid?
本文介绍了如何检查路径是否有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个加载设置的程序,我想知道限制用户输入文本框的无效路径的最佳/简单方法是什么
i am creating a program that loads settings, i want to know what is the best/ easy way to restrict users from entering an invalid path to the textbox
推荐答案
尝试:
Try:
if (!Directory.Exists(path))
{
// Report problem
...
}
您不能限制用户,但您可以警告他们输入了无效路径。实际上,这是错误的,您可以使用浏览器对话框来限制用户 [ ^ ]不允许写入文本框
检查无效路径的方法(如果你不想使用BrowserDialog)
You cannot restrict users, but you can warn them they entered invalid path. Actually, that is wrong, you can restrict users by using Browser Dialog[^] without allowing writing into the Textbox
The way to check for invalid path (if you don't want to use BrowserDialog)
if (System.IO.Directory.Exists() ) {
MsgBox("You entered invalid folder path!", MsgBoxStyle.Exclamation);
}
将上面的支票放入文本框验证活动中。
如果这有帮助,请花些时间接受解决方案。谢谢。
Put the check above in textbox validating event.
If this helps, please take time to accept the solution. Thank you.
存在文件
File exists
if (!File.Exists(path))
{
// Report problem
...
}
文件夹存在
Folder exists
if (!Directory.Exists(path))
{
// Report problem
...
}
这篇关于如何检查路径是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文