How to open IE with post info in C#?

后端 未结 6 1262
陌清茗
陌清茗 2020-12-03 12:32

I am developing a small program which as a windows form. On this form, I want to put a link, and when user click the link, a seperate IE browser will be open with post data.

6条回答
  •  死守一世寂寞
    2020-12-03 12:44

    You are definitely going to need to use Process.Start (or use a ProcessInfo) to get IE started : like this :

    // open IE to a file on the Desktop as a result of clicking a LinkLabel on a WinForm

    internal static string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
    
    private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
    {
        System.Diagnostics.Process.Start("IExplore.exe", desktopPath + "\\someHTMLFile.htm");
    }
    

    If you scroll down in this page :

    http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start(VS.80).aspx

    (the Process.Start docs for FrameWork 3.0)

    you'll find a user contributed example of using ProcessInfo to control whether more than one of instance of IE is started, and how to pass command line arguments to IE.

    This page :

    http://msdn.microsoft.com/en-us/library/0w4h05yb.aspx

    (the Process.Start docs for FrameWork 3.5)

    shows you a complete example of launching IE, and how to pass url files as arguments.

    I'm not completely clear on what you mean by "Post" in your message (I associate "Post" with ASP.NET), but you could write out an html file in a temporary location with whatever you liked in it, and then pass the address of that file when you launch IE using the techniques documented above. best,

提交回复
热议问题