开发者

Submit file in form from C#

I 开发者_如何转开发have a WinForms C# application. There is a WebBrowser control on the form named "browser".

Also I have following code:

            HtmlDocument doc = browser.Document;

            HtmlElement mForm = doc.GetElementById("TheFormId");

            doc.GetElementById("Name").SetAttribute( "value", "Some Name" );

            HtmlElement elFile = doc.GetElementById( "TheFile" );
            elFile.Focus();
            SendKeys.Send( "C:\\1.txt" );

            mForm.InvokeMember( "submit" );

The problem is that it does not submit a file. If I manually type in file name in the corresponding input box - it works.

Environment: Win XP SP2, IE6, VS 2008

Edit: This fixed the problem:

SendKeys.Send( "C:\\1.txt" + "{ENTER}" );


I think this might help:

C# .NET Uploading file to a web form using HttpWebRequest


Does your <form> element have the enctype="multipart/form-data" attribute? You need this to upload files in a form.


This fixed the problem:

SendKeys.Send( "C:\\1.txt" + "{ENTER}" );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜