本文介绍了的Process.Start含参数空间对XP的问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面code段运行很好地在Windows Vista或Windows 7,但不能在XP:

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 + "\"");

但问题是,在Windows XP上的文件名包含空格(C:\ Documents和Settings ...),等等XP Excel中只是显示错误可以'T打开C:\ documents.xls

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".

在Windows Vista和7它甚至可以当我设置的路径/文件名含有一些空间。

On Windows Vista and 7 it even works when I set the path/filename to something containing spaces.

有没有办法来改变参数,以便它会打开Windows XP上也一样,否则我将不得不改变对我的所有客户端的计算机的临时目录?

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?

推荐答案

我没有Excel在我的WinXP SP2 x64的记事本,但即使工作不带引号的:

I don't have Excel on my WinXP x64 SP2 but notepad worked even without quotes:

string filename = Path.ChangeExtension(Path.GetTempFileName(), ".html");
File.AppendAllText(filename, "Test");

System.Diagnostics.Process.Start("notepad.exe", filename);

但是,如果它不为你工作,我认为这是值得尝试设置工作目录,并提供了该文件的名称:

But if it is not working for you I think it is worth trying to set working directory and provide only the file name:

string filename = .Path.ChangeExtension(Path.GetTempFileName(), ".html");
File.AppendAllText(filename, "Test");

System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo()
{
    Arguments = Path.GetFileName(filename),
    WorkingDirectory = Path.GetDirectoryName(filename),
    FileName = "excel.exe"
});

这篇关于的Process.Start含参数空间对XP的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 15:35