简体   繁体   English

如何以编程方式将本地文件路径设置为网页的文件上传器

[英]how to programmatically set local file path to file uploader of a web page

i wan to write a simple program to automatically attach the file to the file uploader of a web page. 我想写一个简单的程序,将文件自动附加到网页的文件上传器上。 i try some methods, but there are not working. 我尝试了一些方法,但是没有用。 i had tried to set the value attribute of the file input, but this method is not working. 我试图设置文件输入的value属性,但是此方法不起作用。

VB.Net VB.Net

temp.SetAttribute("value", "D:\test.jpg")

i also tried to use the windows api to set the file path to the text box of the pop out windows of the file selector, but i hang at the last time that click the open button. 我也尝试使用Windows API将文件选择器的弹出窗口的文本框设置为文件路径,但是我最后一次单击“打开”按钮时挂起。 the click function is not working for the button. 单击功能不适用于该按钮。

VB.Net VB.Net

Private Const WM_KEYDOWN = &H100  
Private Const WM_KEYUP = &H101  
Private Const WM_CHAR = &H102  
Private Const WM_LBUTTONDOWN = &H201  
Private Const WM_LBUTTONUP = &H202  

SendMessage(Button, WM_LBUTTONDOWN, 0, 0)  
SendMessage(Button, WM_LBUTTONUP, 0, 0)  
SendMessage(Button, WM_KEYDOWN, System.Windows.Forms.Keys.Return, 0)
SendMessage(Button, WM_CHAR, System.Windows.Forms.Keys.Return, 0)  
SendMessage(Button, WM_KEYUP, System.Windows.Forms.Keys.Return, 0)

any 1 know the way to set the file url to file input? 任何1知道将文件url设置为文件输入的方法吗?

The file upload control has special protection to stop hackers using it, you can't set it's value in code, and it could well be blocking what you're trying to do here, too. 文件上载控件具有special protection to stop hackers using it,您不能在代码中设置其值,而且很可能也会阻止您在此处尝试执行的操作。

Its not possible 这是不可能的
But if you already know or defined the file location and it really exists than try using System.IO.File.Move() function 但是,如果您已经知道或定义了文件位置并且确实存在,则可以尝试使用System.IO.File.Move()函数

For automation purposes, it's possible to provide a file name with SendKeys . 为了自动化,可以使用SendKeys提供文件名。 The trick is to use a timer event or Task.Delay for asynchronous execution to let the file dialog open first. 诀窍是使用计时器事件或Task.Delay进行异步执行,以首先打开文件对话框。 Here is a working example in C# , it should not be a problem to convert it to VB.NET. 这是C#中的一个有效示例,将其转换为VB.NET应该不是问题。

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

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