Hi ,
i want to write a file to C:\\Program Files\\ using c#
Here is what i have

string currentsnap = "C:\\Program Files\\currentsnap.txt";
  commandtorun("route print > " + currentsnap);

command to run funtion is given below

private static void [B]commandtorun[/B](string commandexecuted)
        {

            string currentstatus;
            ProcessStartInfo startInfo = new ProcessStartInfo();
            Process myprocess = new Process();
      
      
                startInfo.FileName = "cmd"; //
                startInfo.RedirectStandardInput = true;
                startInfo.RedirectStandardOutput = true;
                startInfo.UseShellExecute = false; //'required to redirect
                startInfo.CreateNoWindow = true; // '<---- creates no window, obviously
                myprocess.StartInfo = startInfo; //
                myprocess.Start(); //
                System.IO.StreamReader SR;
                System.IO.StreamWriter SW;
                Thread.Sleep(200);
                SR = myprocess.StandardOutput;
                SW = myprocess.StandardInput;
                SW.WriteLine(commandexecuted); // 'the command you wish to run.....
                SW.WriteLine("exit"); // 'exits command prompt window
                Thread.Sleep(200);
                currentstatus = SR.ReadToEnd();
             
                SW.Close();
                SR.Close();
                //  return currenttable;
            }
}

I am able to write to c:\\ folder , but not to c:\\program files. I think the problem is with the space between program and files

Edited 6 Years Ago by makdu: n/a

i got the solution

commandtorun("route print > " + "\"" + currentsnap + "\"");
This question has already been answered. Start a new discussion instead.