Skip to Content
avatar image
Former Member

Upload File Programetically Using OLE Object to WebBrowser

Hi All.

I want to upload file authenticated website using OLE method from PowerBuilder to WebBrowser. Below is my step which i have tried.

I am able to navigate the url, login and go to particular URL. Now I have struck at file upload level.

Variable type is coming as 'file' [Red  Marked Line ], how to pass file path and name from PB. Below is my script

IE = CREATE OLEObject
IE.ConnectToNewObject("InternetExplorer.Application")

IE.left=200
IE.top=200
IE.height=400
IE.width=400
IE.menubar=1
IE.toolbar=1
IE.statusBar=1
IE.navigate("http://www.xyz.in/index.php")

  1. IE.visible=1
    SetForegroundWindow( IE.HWND )

    DO WHILE IE.Busy
    Yield ()
    LOOP

li_form_ctr = IE.Document.Forms.Length
if li_form_ctr = 1 then
li_form_ctr = li_form_ctr - 1
IE.Document.Forms[li_form_ctr].Elements.username.Value = 'Test'
IE.Document.Forms[li_form_ctr].Elements.password.Value = 'test@123'
ls_OldURL = IE.LocationURL
IE.Document.Forms[li_form_ctr].Elements.submit.Click()
else
return
end if  
DO WHILE IE.Busy
Yield ()
LOOP
if ls_OldURL = IE.LocationURL then
messagebox("Error","Either User Name/Password Wrong")
else
IE.navigate("http://www.xyz.in/upload_ecr_latest.php")
DO WHILE IE.Busy
Yield ()
LOOP
sleep(2)
li_form_ctr = 0
li_form_ctr = IE.Document.Forms.Length
if li_form_ctr = 1 then
li_form_ctr = li_form_ctr - 1
  IE.Document.Forms[li_form_ctr].Elements.month.Value = '08'
  IE.Document.Forms[li_form_ctr].Elements.year.Value = '2014'
IE.Document.Forms[li_form_ctr].Elements.ecr = "D:\temp\xyz.txt" -- This one is not working
ls_OldURL = IE.LocationURL
IE.Document.Forms[li_form_ctr].Elements.upload.Click()
else
return
end if      
end if 

Narayana

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Dec 22, 2014 at 01:41 PM

    AFAIK, you can't set the value for input type =  "file" by script because of security reasons.

    Arnd

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Dear Roland,

      Thank you for the reply

      Merry Christmas!!!

      I have uploaded post.asp to my local website and it is working fine using post.asp. But i am trying to upload file to Government statutory website which fails. Even-though i am go-ogling and trying alternative method but no success. If you find any method please update me, thanks in advance

      Narayana