0

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 Answer 1

7
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"
        );
    }
}
Sign up to request clarification or add additional context in comments.

4 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.