來自MSDN文件:http://msdn.microsoft.com/en-us/library/h6ak8zt5.aspx
// Opens urls and .html documents using Internet Explorer.
void OpenWithArguments()
{
// url's are not considered documents. They can only be opened
// by passing them as arguments.
Process.Start("IExplore.exe", "www.northwindtraders.com");
// Start a Web page using a browser associated with .html and .asp files.
Process.Start("IExplore.exe", "C:\\myPath\\myFile.htm");
Process.Start("IExplore.exe", "C:\\myPath\\myFile.asp");
}
編輯: AaronLS讓你更清楚你想要完成什麼。 傳遞多個參數
Process myProcess = new Process();
string arg = String.Format("{0} {1}{2}{1} {1}{3}{1}", dr["rec"], '"',htmlVar);
myProcess.StartInfo.FileName = @"E:\Program Files\MyApp.exe";
myProcess.StartInfo.Arguments = ArgvToCommandLine(new string[] { arg });
myProcess.Start();
下面的方法是從MSDN頁面採取的ProcessStartInfo參數:http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.arguments.aspx
public static string ArgvToCommandLine(IEnumerable<string> args)
{
StringBuilder sb = new StringBuilder();
foreach (string s in args)
{
sb.Append('"');
// Escape double quotes (") and backslashes (\).
int searchIndex = 0;
while (true)
{
// Put this test first to support zero length strings.
if (searchIndex >= s.Length)
{
break;
}
int quoteIndex = s.IndexOf('"', searchIndex);
if (quoteIndex < 0)
{
break;
}
sb.Append(s, searchIndex, quoteIndex - searchIndex);
EscapeBackslashes(sb, s, quoteIndex - 1);
sb.Append('\\');
sb.Append('"');
searchIndex = quoteIndex + 1;
}
sb.Append(s, searchIndex, s.Length - searchIndex);
EscapeBackslashes(sb, s, s.Length - 1);
sb.Append(@""" ");
}
return sb.ToString(0, Math.Max(0, sb.Length - 1));
}
private static void EscapeBackslashes(StringBuilder sb, string s, int lastSearchIndex)
{
// Backslashes must be escaped if and only if they precede a double quote.
for (int i = lastSearchIndex; i >= 0; i--)
{
if (s[i] != '\\')
{
break;
}
sb.Append('\\');
}
}
這不是最有效的解決您的問題,但我只是複製代碼,以便你可以看到如何正確地轉義可能存在於你的htmlvars變量中的字符。
什麼是HTML? – ChrisF 2010-04-09 21:25:58
是的,發佈dr [「rec」],htmlVar和主題的示例值,因爲這會產生很大的差異。使用編輯按鈕添加您的更改。 – AaronLS 2010-04-09 21:39:05