hi,
iam trying to open up an excel sheet from a batch file using my c# code. I did this by opening the command prompt and reading the batch file contents and writing on the cmd window to execute it. Now when i separately run the batch file, it opens up the excel sheet, so the bat file is correct.But when i do this from my code, the excle sheet does not open, but i can see EXCEL.EXE being run by aspnet in my taskmanager. why cant i see the excel opening up after i run my code?
here is the code iam using:
try
{
ProcessStartInfo psi = new ProcessStartInfo("cmd.exe"
);
psi.UseShellExecute = false;
psi.RedirectStandardOutput
= true;
psi.RedirectStandardInput = true;
psi.RedirectStandardError = true;
psi.WorkingDirectory = @"C:\TEST\";
// Start the process
Process proc = Process.Start(psi);
StreamReader strm = File.OpenText(@"c:\TEST\ne
w.bat");
// Attach the output for reading
StreamReader sOut = proc.StandardOutput;
// Attach the in for writing
StreamWriter sIn = proc.StandardInput;
// Write each line of the batch file to standard input
while(strm.Peek() != -1)
{
sIn.WriteLine(strm.ReadLin
e());
}
sIn.WriteLine("EXIT");
proc.Close();
}
catch (System.Exception ex)
{
Console.WriteLine (ex.Message);
}
when i debug the code, it does not go to the catch block which means it is not encountering any error, but still the excel does not seem to open! the task manager though shows that excel.exe was triggered by aspnet.
pls suggest what can be wrong. i need this very urgently..
thanks in advance.
Start Free Trial