如何检查文本框中是否存在文件名或路径 [英] how to check if a file name or path exists in a textbox

查看:110
本文介绍了如何检查文本框中是否存在文件名或路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我目前正在完成第一个成功的项目,但仍然需要一些有关Bug的帮助.在我的项目中,您可以在其中输入TextBox(搜索框"),以便用户可以启动他们键入的程序名称或路径.问题是当文件名或路径不存在时,我得到了默认的错误提供程序.为了使事情专业,我想做一个if语句,以便如果文件名或路径不存在,则会出现一个MessageBox并带有我自己的错误消息.

摘要:该程序是一个窗口储物柜.基本上,您打开一个程序,然后应用程序捕获该窗口.该应用程序的表单设置为在最前面,因此当您使用全屏程序时,它不会隐藏.我做到了,这样我就可以一边玩游戏,一边与媒体播放器打交道,而不必进行切换.我确信它对其他人特别有用,特别是我添加了一些很酷的功能.就像不透明度跟踪栏一样,它允许用户操纵应用程序窗体的不透明度,因此您仍然可以看到正在执行的操作的背景.

主题外:该网站是否允许用户提交项目?我的应用程序没什么大不了,但是它仍然可以是有用的,并且是免费的.如果没有,哪些网站好?

完成后,我将在完成后发布网站链接,以便您下载.

程序是Winform,用C#编写.

在此先感谢,

Hi, I am currently finishing up my first successful project but I still need some help with a bug. In my project your able to type in a TextBox("search box") that TextBox is there so that users can start which ever program name or path they type. The problem is that I get a default error provider when the file name or path does not exists. To keep things professional I want to make an if statement so that if the file name or path does not exists a MessageBox will appear with my own error message instead.


Summary: the program is a window locker. basically you open a program and the application captures the window. the application''s form is set to be up front so it wont hide when you are on a full screen program. I made it so that I can play games while messing around with the media player without having to tab. I''m sure it will be useful to others especially with some cool features I added. Like an opacity trackbar that allows users to manipulate the opacity of the app''s form so you can still see the background of what you are doing.

Off Topic: Does this site allows users to submit projects? My application is nothing big but it still can be useful, and its free. If not, what sites are good?

When completed I will post the link of the site when I''m done so you can download.

program is a winform and is written in C#

Thanks in advance,

推荐答案

尝试一下

Try this

using System;
using System.IO;

class Program
{
    static void Main()
    {
    // See if this file exists in the SAME DIRECTORY.
    if (File.Exists("TextFile1.txt"))
    {
        Console.WriteLine("The file exists.");
    }
    // See if this file exists in the C:\ directory. [Note the @]
    if (File.Exists(@"C:\tidy.exe"))
    {
        Console.WriteLine("The file exists.");
    }
    // See if this file exists in the C:\ directory [Note the '\\' part]
    bool exists = File.Exists("C:\\lost.txt");
    Console.WriteLine(exists);
    }
}




是的,您可以在codeproject中将您的项目作为文章提交.
另请参阅此论坛中的不同部分,例如wise
对于与编程相关的问答,我们有此部分;对于非编程问答,论坛中有错误和建议"的部分

您可以在这里问非主题"之类的问题,您可以在
找到它 帮助>>错误和建议

希望这会有所帮助,如果是,则接受并投票回答,否则返回您的查询
--Rahul D.




And yes you can submit your project as article in codeproject.
Also see there are different sections in this forum like wise
for question and answer related to programming we have this section and for non-programming question and answer forum has section "Bug and Suggestions"

You can ask here your question like "Off Topic" you will find it in
Help >> Bugs and suggestions

Hope this helps if yes then accept and vote the answer otherwise revert back with your queries
--Rahul D.


尝试:
if (!File.Exists(path))
   {
   ...
   }



脱离主题-是的,如果您很好地解释了代码,并且很有趣,则可以将其作为文章提交.在屏幕左上方的菜单栏上的文章"下查看.请注意,尽管一篇文章有​​很多工作要做,但您不能只是发布您的代码并希望它会被接受-它不会!看看一些现有的文章,您会明白我的意思.



Off topic - yes, if you explain your code well, and it is interesting, you could submit it as a article. Have a look under "Articles" on the menu bar in the top left of the screen. Be aware though that an article is a lot of work, you can''t just post up your code and hope it will be accepted - it won''t! Have a look at a few of the existing articles, and you will see what I mean.


这篇关于如何检查文本框中是否存在文件名或路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆