Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Process.Start parameter containing spaces has problems on XP?

Tags:

c#

.net

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?

like image 722
Sam Avatar asked Aug 12 '26 08:08

Sam


1 Answers

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.

like image 170
ChrisF Avatar answered Aug 13 '26 21:08

ChrisF



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!