Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add Download Ability to Your App in 2 Seconds

Internet

Add Download Ability to Your App in 2 Seconds

by  craigsboyd  Posted    (Edited  )
Slighthaze = [color blue]NULL[/color]
[img http://www.sweetpotatosoftware.com/ttimages/download.gif]
Code:
I stumbled on the below method and couldn't believe how simple it was.  Download with progress indication and everything.  I have made some revisions since this FAQ was first posted, thanks to machele for asking all the right questions. 
 
This program can handle username/password and unsafe characters in the URL.  An example of a fullblown URL for this program would be something like [b]sURLandFile = "ftp://username:password@domain/Some Path/Some File I Want.zip"[/b] <-- note that the path and filename have spaces in them (space is an unsafe URL character that needs to be turned into escape sequences - see HandleUnsafeChars function below)

***(Cut-n-paste the code into a prg file and run from within VFP)***

Local sURLandFile, nRet

Declare DoFileDownload IN shdocvw.dll STRING lpszFile 

sURLandFile = "ftp://ftp.microsoft.com/deskapps/readme.txt";

sURLandFile = HandleUnsafeChars(sURLandFile)

IF !EMPTY(sURLandFile)
    nRet=DoFileDownload(STRCONV(sURLandFile,5))
ELSE
    MESSAGEBOX("Function returned an empty length string.",16,"Something is Wrong")
ENDIF

************************
FUNCTION HandleUnsafeChars(sAddressUrl)
***Purpose: Change unsafe chars to escape sequences
************************
    #DEFINE ICU_BROWSER_MODE 33554432 && 0x2000000 

    DECLARE INTEGER InternetCanonicalizeUrl IN wininet; 
        STRING sURL, STRING @sBUFFER, INTEGER @nLength, INTEGER nFlags 

    LOCAL sNewUrl, nResult 

    nResult = 250 
    sNewUrl = Replicate(Chr(0), nResult) 

    IF InternetCanonicalizeUrl (sAddressUrl,@sNewUrl, @nResult, ICU_BROWSER_MODE) <> 0 
        RETURN Left(sNewUrl, nResult)
    ELSE
        RETURN ""
    ENDIF 
    
ENDFUNC &&HandleUnsafeChars
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top