开发者

How to pass arguments to an HtmlFile?

开发者 https://www.devze.com 2022-12-29 06:08 出处:网络
How to pass a开发者_如何转开发rguments to an HtmlFile fromC#? Like: System.Diagnostics.Process.Start(\"Sample.html\",\"Arguments\");

How to pass a开发者_如何转开发rguments to an HtmlFile from C#?

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

If I execute the above code the "Sample.html" file should be opened and it should do something with the "arguments".


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

UPDATE:

To figure out the default browser location:

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"
        );
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号