Skip to Content
0
Former Member
Dec 22, 2014 at 07:34 AM

Upload File Programetically Using OLE Object to WebBrowser

234 Views

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