tags:

views:

54

answers:

1

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".

+6  A: 
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"
        );
    }
}
Darin Dimitrov
You’ll get +1 as soon as you determine the correct standard browser’s path. ;-)
Konrad Rudolph
@Konrad, see my update :-)
Darin Dimitrov
Thanks Darin Dimitrov
Pramodh
But how to get the "value1" in the html file using javascript....if you dont mind can please explain that too?
Pramodh
@Pramodh, you may take a look at this article: http://www.netlobo.com/url_query_string_javascript.html It shows a function you could use to read parameters passed in the URL.
Darin Dimitrov
:-) fine thank you.... i got an idea... var url = window.location.search.substring(1) var arr=url.split("=") str=arr[1]
Pramodh