Reading the text file and calling from menu

madhugp

Member
Joined
Nov 27, 2017
Messages
9
Programming Experience
5-10
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
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,272
Location
Sydney, Australia
Programming Experience
10+
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.
 
Top Bottom