Results 1 to 3 of 3

Thread: Reading the text file and calling from menu

  1. #1
    .NET Framework
    .NET 4.5
    Join Date
    Nov 2017
    Posts
    9
    Rep Power
    0

    Reading the text file and calling from menu

    HI Friends,

    I am trying to call the windows forms through menu strip.
    In menu strip items i have written the following code
    which reads a text file "rep_path.txt".
    the text file contains only line d:\\reports\\

    private void SALEPRODToolStripMenuItem_Click(object sender, EventArgs e)
    {

    string str = System.IO.File.ReadAllText(@"d:\rep_path.txt");


    Process myProcess = new Process();

    myProcess.StartInfo.FileName = str+"sale_prod.exe";

    myProcess.Start();



    }

    on cliking of this menu item it shows the following exception and message.

    An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll

    Additional information: The system cannot find the file specified


    but if i use the path directly for the filename then it is working.

    myProcess.StartInfo.FileName = "d:\\reports\\sale_prod.exe";

    plz give the solution for this problem.

    thanks and regards

    Madhu

  2. #2
    .NET Framework
    .NET 4.5
    Join Date
    Apr 2011
    Posts
    1,998
    Rep Power
    155
    When you use double slashes in C# code it is because you need to escape the slash character IN C# CODE. If you have text in a file you don't put double slashes in it because a text file is not C# code. Think about it. If you want a line break in a text file do you put \r\n into the text? Of course you don't. That's just something you do in C# code. This is exactly the same.

  3. #3
    .NET Framework
    .NET 4.5
    Join Date
    Nov 2017
    Posts
    9
    Rep Power
    0
    HI thanks for the suggestion , it is working now

Similar Threads

  1. How to check for null while reading from file
    By Digimstr in forum C# General Discussion
    Replies: 1
    Last Post: 12-02-2014, 11:02 PM
  2. Error reading a file
    By Romulo in forum C# General Discussion
    Replies: 2
    Last Post: 01-16-2014, 1:18 PM
  3. StreamReader not reading to end of text file
    By inkedGFX in forum C# General Discussion
    Replies: 11
    Last Post: 10-05-2013, 8:07 AM
  4. Replies: 1
    Last Post: 03-13-2012, 7:04 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •