如何将参数传递给HtmlFile?

时间:2010-05-07 10:56:27

标签: c# .net .net-3.5

如何从C#传递参数到HtmlFile?

赞:System.Diagnostics.Process.Start("Sample.html","Arguments");

如果我执行上面的代码,应该打开“Sample.html”文件,它应该用“参数”做一些事情。

1 个答案:

答案 0 :(得分:8)

Process.Start(
    @"C:\Program Files\Internet Explorer\iexplore.exe", 
    "file:///c:/path/to/file/Sample.html?param1=value1"
);

更新:

找出默认的浏览器位置:

class Program
{
    [DllImport("shell32.dll")]
    public extern static int FindExecutable(
        string forFile, 
        string directory, 
        StringBuilder result
    );

    static void Main(string[] args)
    {
        var browserLocation = new StringBuilder(1024);
        // make sure you specify the correct path and the file actually exists
        // or the FindExecutable will return an empty string.
        FindExecutable(@"d:\work\html\index.htm", null, browserLocation);

        Process.Start(
            browserLocation.ToString(),
            "file:///d:/work/html/index.htm?param1=value1"
        );
    }
}