2

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.

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. the click function is not working for the button.

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?

noseratio
  • 59,932
  • 34
  • 208
  • 486
e-qi
  • 135
  • 2
  • 3
  • 13
  • Just to be clear, are you interacting with a `WebBrowser` control or something similar in a client application? Or are you trying to do this from server-side code in a web application? – David Sep 26 '13 at 16:26
  • interacting with a WebBrowser in the windows application – e-qi Sep 26 '13 at 16:38

2 Answers2

-1

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.

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

Ramesh Yadav
  • 143
  • 1
  • 2
  • 9
-1

For automation purposes, it's possible to provide a file name with SendKeys. The trick is to use a timer event or Task.Delay for asynchronous execution to let the file dialog open first. Here is a working example in C#, it should not be a problem to convert it to VB.NET.

Community
  • 1
  • 1
noseratio
  • 59,932
  • 34
  • 208
  • 486