Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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,
Posted
Updated 12-Feb-12 15:29pm
v4
Comments
Ganesan Senthilvel 12-Feb-12 7:10am    
Title and question title are misleading.

Try this

C#
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);
    }
}



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.
 
Share this answer
 
Comments
NeptuneHACK! 12-Feb-12 10:03am    
5
MR. AngelMendez 12-Feb-12 21:34pm    
thanks for the help everyone, is there a way to implement it for a winform? also, I noticed that your code only checks for a specific file, is there a way to make it check if the text in the textbox equals an existing file name?
krumia 12-Feb-12 22:35pm    
replace the file name with this code: txtTextBox.Text it's as simple as that!
MR. AngelMendez 13-Feb-12 12:08pm    
cool it worked but I got another problem, how can I make an "if" statement that will handle an error message when the file does NOT exists?
RDBurmon 14-Feb-12 1:35am    
if (File.Exists("TextFile1.txt"))
{
Console.WriteLine("The file exists.");
}
else
{
Console.WriteLine("The file does not exists.");
}
Try:
C#
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900