如何将参数传递给HtmlFile? [英] How to pass arguments to an HtmlFile?

查看:90
本文介绍了如何将参数传递给HtmlFile?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How to pass arguments to an HtmlFile from C#?

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

如果执行上面的代码,则应打开"Sample.html"文件,并使用自变量"执行某些操作.

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


更新:

要找出默认的浏览器位置,请执行以下操作:

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

这篇关于如何将参数传递给HtmlFile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆