Link to home
Start Free TrialLog in
Avatar of orion_solutions
orion_solutions

asked on

Downloading file from internet in vb6

Hello Experts, I'm downloading a .csv file from a site, through vb6 code.
When the file is downloaded, IE shows "File Download" DialogBox, from where user can click on "save" Button, to save the file on LocalHDD.

I want the path of the File saved on LocalHDD!!! OR Is there any way to Download the file to a specific folder SILENTLY (means without showing FILE DOWNLOAD DialogBox to the User).

I'm Using "Inet" control in vb6.

Hope you have understood my problem.

Regards
Sukhdev

Avatar of DarkoLord
DarkoLord
Flag of Slovenia image

Which method are you calling to download a file?
Avatar of orion_solutions
orion_solutions

ASKER

Following r the 2 functions to download the file:

1>>
Private Function doHistory()
Dim doc As HTMLDocument
Dim u  As String
WebBrowser1.Navigate "https://history.paypal.com/uk/cgi-bin/webscr?cmd=_history-download"
  Do
    DoEvents
    Loop Until Not WebBrowser1.Busy
    Set doc = WebBrowser1.Document        
        SetInputField doc, 0, "from_b", from_b
        SetInputField doc, 0, "from_a", from_a
        SetInputField doc, 0, "from_c", from_c
         
        SetInputField doc, 0, "to_b", to_b
        SetInputField doc, 0, "to_a", to_a
        SetInputField doc, 0, "to_c", to_c
         
        SetComboTextValue doc, 0, "custom_file_type", format
        '--------------------------------------
        If doc.Forms.length = 0 Then
            Exit Function
        Else
            doc.Forms(0).submit
        End If
           
            Do
                DoEvents
                Loop Until Not WebBrowser1.Busy
                clickButton doc, 0, "submit.x"   ****** This were it call to another function : ClickButton()
End Function

2>>

Public Function clickButton(ByVal doc As IHTMLDocument3, Form As Integer, Name As String)
    Dim q, i
    For q = 0 To doc.Forms(Form).length - 1
        If (doc.Forms(Form)(q).Name = Name) Then
            doc.Forms(Form)(q).Click
        Exit For
        End If
        Next q
    End Function
ASKER CERTIFIED SOLUTION
Avatar of DarkoLord
DarkoLord
Flag of Slovenia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
However, he appears to be filling in some fields on the page... He would need to GET/POST using correct parameters (and cookies) using the Inet control..
>>He would need to GET/POST using correct parameters ...

Yes.   I haven't seen the paypal page itself, but it is likely that the form submit action is the URL to the csv, or a link that returns the csv file, thus he can use the form action as the URL for inet.

Alternatively, you CAN turn off the prompt for the "download this file" prompt, and you can probably figure out where the file will be downloaded by the default path of the browser control.  I have code that does this , somewhere....
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you can use the application curl. it is a small application that will allow  you to download the http file with a get/post data.

from vb6 generate the dynamic scripts and fwd that as input to curl. you can also perform ftp.
1. if the web site you want t0 download does not verify the source then, make a local html file with the required form and default data.
2. on body onLoad
submit the form
Dear DarkoLord can you tell me where to call the timer code in my App????

I have disabled the Timer and is calling in the ClickButton() Function : Timer1.Enabled = True

and i still get the File Download Dialog!!!

Can u tell me what i'm doing wrong??

Reagards
heres the brief explaination what i'm doing :

My App Accepts PayPal UserName, Password from the user, Loggs in on PayPal and Download the Transaction History from that PayPal Account.
Then i have to Save this .CSV file to MS-Access Database.
Now, the Code is working Fine, JUST THAT THE "FILE DOWNLOAD" dialog box is shown.
I want Either of the Two things done :

1>> i want the File Download Dialog box disappear and want the .CSV file to be saved on a specific location on LocalHDD, So that i can import the data from this .CSV file to my Access Database.

                                                                          OR

2>> If File Download does not Disappear, Atleast i want the PATH where the user is SAVING the .CSV file!!!
Please let me be Clear, that i'm not downloading any HTML file, I'm Logging the PayPal site by filling the Username and Password, then i'm going to History Page on PayPal, then i'm downloading the TRANSACTIION HISTORY, in .CSV file.
Dear DarkoLord - I THINK UR (TIMER) CODE IS WORKING!!!! but it has a problem, here what i did:

I made the timer enabled on Form_Load, and is enable throughout the process.

Only problem is that now, the FILE DOWNLOAD box Appears for a Flash of a second and then Disappears. I think when u r sending keys to the File Download :
SendKeys "{ENTER}" - is actually Cancelling the Download, coz the DEFAULT BUTTON SELECTED ON FILE DOWNLOAD DIALOG BOX IS "CANCEL", CAN YOU MODIFY THE CODE SO THAT IT CLICKS "SAVE" BUTTON??
Dear DarkoLord i have modified ur code and it is working, although it still shows File Download dialog box and "Save" dialog box, but they disappears as the timer code continue!!!!

Here's is the modified code :

Private Sub Timer1_Timer()
winWndDl = FindWindow(vbNullString, "File Download")
winWndDlD = FindWindow(vbNullString, "Download complete")

If winWndDl > 0 Then
'sends enter key to hit save
SendKeys "{LEFT}"   '************* I made this to Click the "Save" Button, coz Save Button is on the Left side of the "Cancel" Button '***********
SendKeys "{ENTER}"
'fils in the file path\name txtbox
SendKeys VarDownloadPath & "download.csv"  '****** here i was getting error that the Path does not Exists!!! It requires a Fixed path, that means the Folder Must me Present on the Physical Location '******
'send enter command to start download
SendKeys "{ENTER}"
End If

'Closes the download complete box
'after download is done.
If winWndDlD > 0 Then
SendKeys "{ENTER}"
End If
End Sub

Thanks for ur Professional Help!!!!

Best Regards and Best of Luck for ur Future Questions
sukhdev singh
(sukhdev_v@rediffmail.com)
If you think the period that the File Download dialog box shows for is too long, you can decrease the timer's interval.

Also, you can disable timer when not needed and enable it when you start downloading the file