The following code snippet runs nicely on windows vista or windows 7, but not on XP:
String filename = System.IO.Path.ChangeExtension(System.IO.Path.GetTempFileName(), ".html");
[...write file...]
System.Diagnostics.Process.Start("excel.exe", "\"" + filename + "\"");
Problem is, on Windows XP the filename contains spaces ("c:\documents and settings..."), so on XP Excel just shows the error "can't open c:\documents.xls".
On Windows Vista and 7 it even works when I set the path/filename to something containing spaces.
Is there a way to change the parameters so it will open on windows XP, too, or will I have to change the temp directory on all my clients computers?
Try using:
Process excelProcess = new Process();
excelProcess.StartInfo.FileName = "excel.exe";
excelProcess.StartInfo.Aguments = "\"" + filename + "\"";
excelProcess.Start();
I know this code works with spaces in the filename.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With