NOT creating new .txt file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Toboe
    New Member
    • Nov 2009
    • 2

    NOT creating new .txt file

    I have a slight problem. The idea with this part is that the program open a .txt file witch name you type in. It works. The problem is, if you type in a name of file that does not exist, it still opens notepad and ask if I want to create a new document with the name you gave. If the file does not exist, a message box or something similar should show up. Please advice. Thanks :)

    [code=c]private void button3_Click(o bject sender, EventArgs e)
    {
    if (TextBox1.Text != "")
    {
    try
    {
    System.Diagnost ics.Process.Sta rt("notepad.exe ", TextBox1.Text);
    }
    catch (Exception excep)
    {
    MessageBox.Show (excep.ToString ());
    }
    }[/code]
  • cloud255
    Recognized Expert Contributor
    • Jun 2008
    • 427

    #2
    Try using the System.IO.File. Exists method to see if the file does exist before starting the process.

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      Check to see if the file exists before you try to pass it off to Notepad.

      System.IO.File. Exists(string PathToFile)

      Comment

      • Toboe
        New Member
        • Nov 2009
        • 2

        #4
        Great, got it working as intended now. Thanks for your help! :D

        Comment

        Working...