简体   繁体   English

如何使用VB.Net通过Webbrowser将图像文件上传到网站

[英]How to upload a image file to a web site through webbrowser with VB.Net

I'm trying to fill website forms and I can do it with textbox, checkbox, radios, select-combobox, all by code but when I try to upload a image file I only can do it by keyboard pulsation simulation (SendKeys). 我正在尝试填写网站表单,并且可以通过代码,文本框,复选框,单选框,选择组合框来完成此操作,但是当我尝试上传图像文件时,只能通过键盘跳动模拟(SendKeys)来完成。

Is there any way to achieve it using only code? 有什么方法可以仅使用代码来实现? I need to know because I want that my application runs in background. 我需要知道,因为我希望我的应用程序在后台运行。

If its impossible by security reasons, can anybody show me a link with documentation explaining why? 如果由于安全原因无法实现,谁能向我显示说明原因的文档链接?

Thank you all. 谢谢你们。

This is my working code to upload image: 这是我上传图片的工作代码:

 For Each elemento As HtmlElement In WebBrowser1.Document.GetElementsByTagName("input")
            If elemento.GetAttribute("name") = "ad_picture_a" Then
                elemento.Focus()
                SendKeys.SendWait("                 " & Form2.Label6.Text & "{TAB}" & "{TAB}" & "{ENTER}")
                Exit For
            End If
        Next

You can use the SetAttribute() method to set the value attribute of the input-tag. 您可以使用SetAttribute()方法来设置输入标签的value属性。

elemento.SetAttribute("value", "                 " & Form2.Label6.Text & "\t\t\n")

\\t is the tab character, and \\n the a new line character (assuming that you are inputting them, if you are actually trying to move the focus and click something please give me more information about that object). \\t是制表符, \\n是换行符(假设您正在输入它们,如果您实际上是在尝试移动焦点并单击某些内容,请向我提供有关该对象的更多信息)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM