How to pass arguments to an HtmlFile?

北城以北 提交于 2021-02-04 21:53:08

问题


How to pass arguments 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".


回答1:


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


来源:https://stackoverflow.com/questions/2787970/how-to-pass-arguments-to-an-htmlfile

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!